locked
Exception in Sending mail through SMTP RRS feed

  • Question

  • I am trying to send email using SMTP in my web application. It raises exception

    "

    A first chance exception of type 'System.Net.Mail.SmtpException' occurred in System.dll

    "

    i am not using XP smtp service in IIS:

     

    Here is my code any one can help to solve this problem:

     

    protected void SendEmail()

    {

    SmtpClient oSmtp = new SmtpClient("smtp.gmail.com", 465);

    oSmtp.DeliveryMethod = SmtpDeliveryMethod.Network;

    oSmtp.EnableSsl = true;

    oSmtp.Host = "smtp.gmail.com";

     

    MailAddress mFrom = new MailAddress("abc@gmail.com");

    MailAddress mTo = new MailAddress("abcde@gmail.com");

    string mSubject;

    string mBody;

    mSubject = "TestMailer";

    mBody = "This is test mail by <b>" + mSubject + "to implement in ASP;</br>abc";

     

    MailMessage eMsg = new MailMessage(mFrom.ToString(), mTo.ToString(),mSubject,mBody);

     

    eMsg.Priority = MailPriority.High;

    eMsg.IsBodyHtml = true;

     

    try

    {

     

    oSmtp.ServicePoint.ConnectionLeaseTimeout = 1000;

    oSmtp.ServicePoint.MaxIdleTime = 1000;

    oSmtp.Timeout = 1000;

    oSmtp.Send(eMsg);

     

    System.Console.Write("Suceess");

     

    }

    catch (Exception e)

    {

    e.StackTrace.ToString();

    }

    }

    Saturday, May 26, 2007 7:16 AM

Answers

All replies