You must Sign In to post a response.
  • Category: ASP.NET

    Sending Email is not Working Properly-Exactly

    hi Developers,

    May i know any error im my Send Email Code.

    Mail not send properly so i get doubt may any mistake in my code.
    Below am added
    Mail Class:
    public void EmailSend(string frmID, string frmName, string toID, string subMsg, String BodyMsg, bool status)
    {
    SmtpClient smtpclient = new SmtpClient();
    MailMessage message = new MailMessage();
    MailAddress fromAddress = new MailAddress("test@maduraimedicos77.com", "MADURAI MEDICOS 77 ( test@maduraimedicos77.com )");
    smtpclient.Host = "108.163.250.251";
    smtpclient.Port = 25;
    message.From = fromAddress;
    message.To.Add(toID);
    message.Subject = subMsg;
    message.Body = BodyMsg;
    message.BodyEncoding = System.Text.Encoding.ASCII;
    message.IsBodyHtml = status;
    message.Priority = MailPriority.High;
    NetworkCredential ocredential = new NetworkCredential("test@maduraimedicos77.com", "test123");
    smtpclient.EnableSsl = true;
    smtpclient.UseDefaultCredentials = false;
    smtpclient.Credentials = ocredential;
    smtpclient.Send(message);
    }

    Button Click:
    objMail.EmailSend("test@maduraimedicos77.com", ":: LABMATE ASIA.NET::", txtmail.Text.Trim(), "A Mail From :: LABMATE ASIA.NET ::", BodyMessage1(txtmail.Text), true);
    Response.Write("Mail Send");

    in this code mail sends Gmail and yahoo account email accounts only.
    if anyone got any error in my code please suggest me. i want to know my code is whether Exavt or wrong.

    Thanks with
    Paul.S
  • #767359
    Hi,

    Refer the below..

    Sending mail from .Net application

    MailMessage mailMsg = new MailMessage();
    MailAddress mailAddress = new MailAddress("YourMailID@gmail.com");
    mailMsg.To.Add("xyz@gmail.com");
    mailMsg.CC.Add("YourMailID@gmail.com");
    mailMsg.From = mailAddress;
    // Subject and Body
    mailMsg.Subject = "Test mail..Please ignore";
    mailMsg.Body = "Juz i am testing whether messages are sending or not through my dotnet web application...Test mail..Please ignore";
    SmtpClient smtpClient = new SmtpClient("smtp.gmail.com", 25);
    System.Net.NetworkCredential credentials = new System.Net.NetworkCredential("YourMailID@gmail.com", "YourPassword");
    smtpClient.EnableSsl = true;
    smtpClient.UseDefaultCredentials = false;
    smtpClient.Credentials = credentials;
    smtpClient.Send(mailMsg);


    Hope this will help you

    Regards,
    SonyShiva
    Never lose hope..You never know what tomorrow will bring

  • #767360
    Following are the sample code for sending the email from any SMTP server.
    You have to take care of port number. By default it is 25. If you want to send Gmail you have to use "587". Check for other servers.

    MailMessage aMailL = new MailMessage();
    aMailL.From = new MailAddress(TxtFromEmail.Text);

    List<string> zEmailToListP = new List<string>() { TxtToEmail.Text };
    foreach (string zMailAddressL in zEmailToListP)
    {
    aMailL.To.Add(zMailAddressL);
    }

    aMailL.Subject = "Your Subject";

    aMailL.Body = "Your Text";
    aMailL.IsBodyHtml = true;
    SmtpClient TheSmtpClientL = new SmtpClient();
    TheSmtpClientL.Host = zSmtpServerHostL;
    if (nPortNumberL != 0)
    {
    TheSmtpClientL.Port = nPortNumberL;
    }
    if (bIsEnableSSL)
    {
    TheSmtpClientL.EnableSsl = bIsEnableSSL;
    }
    if (zSmtpServerUidL != "" && zSmtpServerPwdL != "")
    {
    TheSmtpClientL.UseDefaultCredentials = false;
    TheSmtpClientL.Credentials = new System.Net.NetworkCredential(zSmtpServerUidL, zSmtpServerPwdL);
    }
    else
    {
    TheSmtpClientL.UseDefaultCredentials = true;
    }
    TheSmtpClientL.Send(aMailL);

    By Nathan
    Direction is important than speed

  • #767390
    I think you will run as expected, but though the code is working well, there are still many factors that will affect mail sending functionality

    1. Firewall block port 587 (This is port for smtp gmail server)
    2. Internet connection is not available on machine or internet connection has face some obstacles while pinging
    3. Due to some typo mistake UserName and password may be get wrong
    4. Enable SSL is block email sending
    5. POP settings for smtp server in your Gmail account is disabled

    Thanks
    Koolprasd2003
    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

  • #767405
    Thanks for all your valuable reply .
    thanks a lot dear friends

    Paul.S


  • Sign In to post your comments