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("", "MADURAI MEDICOS 77 ( )");
    smtpclient.Host = "";
    smtpclient.Port = 25;
    message.From = fromAddress;
    message.Subject = subMsg;
    message.Body = BodyMsg;
    message.BodyEncoding = System.Text.Encoding.ASCII;
    message.IsBodyHtml = status;
    message.Priority = MailPriority.High;
    NetworkCredential ocredential = new NetworkCredential("", "test123");
    smtpclient.EnableSsl = true;
    smtpclient.UseDefaultCredentials = false;
    smtpclient.Credentials = ocredential;

    Button Click:
    objMail.EmailSend("", ":: 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
  • #767359

    Refer the below..

    Sending mail from .Net application

    MailMessage mailMsg = new MailMessage();
    MailAddress mailAddress = new MailAddress("");
    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("", 25);
    System.Net.NetworkCredential credentials = new System.Net.NetworkCredential("", "YourPassword");
    smtpClient.EnableSsl = true;
    smtpClient.UseDefaultCredentials = false;
    smtpClient.Credentials = credentials;

    Hope this will help you

    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.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);
    TheSmtpClientL.UseDefaultCredentials = true;

    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

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

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


  • Sign In to post your comments