Failure in sending mail

+2 Johann Rino · August 17, 2014
I got an error in sending message to mail.

Here's my code:
            MailMessage message = new MailMessage();
            message.From = new MailAddress(EmailAddTxtBx.Text);
            message.Subject = SubjectTxtBx.Text;
            message.Body = BodyTxtBx.Text;
            message.To.Add(RecipiantsTxtBx.Text);
            SmtpClient client = new SmtpClient();
            client.Credentials = new NetworkCredential(EmailAddTxtBx.Text, PasswordTxtBx.Text);
            client.Host = "smpt.gmail.com";
            client.Port = 587;
            client.EnableSsl = true;
            client.Send(message);

And I Got this Error .

" An unhandled exception of type 'System.Net.Mail.SmtpException' occurred in System.dll

Additional information: Failure sending mail. "

Does anyone know how to solve this error ? help me guys:(

Post a Reply

Replies

Oldest  Newest  Rating
+1 Bill Harding · September 2, 2014
try
client.Host = "smTP.gmail.com";
+1 Chris Blum · August 18, 2014
Here's some code I was using for a C# forms application in Visual Studio. May be able to grab some useful info out of this.



try { SmtpClient client = new SmtpClient("xxx.clientserver.com", 555);//555 is port number
client.EnableSsl = true;
client.Timeout = 10000;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.Credentials = new NetworkCredential("youremail@whatever.come", "yourpassword");
MailMessage msg = new MailMessage(); msg.To.Add(sentto@whatever.com);
msg.From = new MailAddress(youremail@whatever.com);
msg.Subject = textBoxSubject.Text; msg.Body = textBoxMessage.Text; client.Send(msg);
MessageBox.Show("Successfully sent message"); }
catch (Exception ex) { MessageBox.Show(ex.Message); }
  • 1

C#

106,989 followers
About

C# is an object-oriented language designed for improving the development of web applications.

Links
Moderators