Question Failure to send email.

Riyaaz

New member
Joined
Oct 14, 2014
Messages
4
Programming Experience
Beginner
Hi
I am sending an email through the my form. It works on my home pc but it doesn't pick up on another pc. I have know clue why.

try
{
SmtpClient client = new SmtpClient("smtp.gmail.com", 587);
MailMessage message = new MailMessage();
message.From = new MailAddress(txtEmailAddress.Text);
message.To.Add(txtSendto.Text);
message.Body = image + head + subHeading + textBox1.Text + spaces + numericUpDown1.Text + spaces + numericUpDown2.Text + spaces + numericUpDown3.Text + fanta + creamSoda + sprite + appletiser + justJuice + grapetiser + chinesejuice + newLine + content;
message.Subject = txtSubject.Text;
message.IsBodyHtml = true;
client.UseDefaultCredentials = false;
client.EnableSsl = true;



client.Credentials = new System.Net.NetworkCredential(txtEmailAddress.Text,txtPassword.Text);
client.Send(message);
message = null;


MessageBox.Show("Message sent!");
}
catch(Exception ex)
{
MessageBox.Show("Failed to send message");
}
}
 

wim sturkenboom

Well-known member
Joined
Aug 6, 2014
Messages
85
Location
Roodepoort, South Africa
Programming Experience
10+
Instead of using
C#:
catch(Exception ex)
            {
                     MessageBox.Show("Failed to send message");
            }
display the real error message (or log it to file). You make yourself blind by hiding the error message.
C#:
catch(Exception ex)
            {
    MessageBox.Show(ex.Message);
            }
 

JohnH

C# Forum Moderator
Staff member
Joined
Apr 23, 2011
Messages
901
Location
Norway
Programming Experience
10+
It says failure sending message
What exception is that, and is that the exact exception message? Possible exceptions are listed here: SmtpClient.Send Method (MailMessage) (System.Net.Mail), notice especially this remark:
documentation said:
If you receive an SmtpException exception, check the StatusCode property to find the reason the operation failed. The SmtpException can also contain an inner exception that indicates the reason the operation failed.
See this for example checking all wrapped exceptions: Troubleshooting System.Net.Mail
 

old_man

Member
Joined
Oct 24, 2016
Messages
17
Location
Michigan USA
Programming Experience
Beginner
I have to tell gmail to let me run my Python emailer.


 

Attachments

  • email.jpg
    email.jpg
    60.1 KB · Views: 61
Top Bottom