Skip to content

Mail sending program issue

George George

Asked Dec 26, 2008, 5:07 PM EST2 answers
Share
LinkedInX

Hello everyone,

I am writing the following program to send a message to my gmail box. There is no

exception, but I can not receive any email in my gmail inbox. Does anyone have any ideas

why?

[Code]
           MailMessage mailMsg = new MailMessage();
            mailMsg.From = new MailAddress("[email protected]");
            mailMsg.To.Add("[email protected]");
            mailMsg.Subject = "Test subject 2";
            mailMsg.IsBodyHtml = true;
            mailMsg.BodyEncoding = Encoding.UTF8;
            mailMsg.Body = "This email is sent from asp.net code";
            mailMsg.Priority = MailPriority.Normal;
            // Smtp configuration
            SmtpClient client = new SmtpClient();
            client.Credentials = new NetworkCredential("[email protected]",

"mypassword");
            client.Port = 587; //or use 465           
            client.Host = "smtp.gmail.com";
            client.EnableSsl = true;
            object userState = mailMsg;
            try
            {
                //you can also call client.Send(msg)
                // client.SendAsync(mailMsg, userState);
                client.Send(mailMsg);
            }
            catch (SmtpException ex)
            {
                Console.WriteLine(ex.ToString());
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }

            return;
[/Code]

thanks in advance,
George

2 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    insted of "[email protected]" give the valied email id in the "To" property
    0
  • 0

    Thanks, your solution works!

    regards,

    George

    0