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);
            }
 

Riyaaz

New member
Joined
Oct 14, 2014
Messages
4
Programming Experience
Beginner
It says failure sending message

Could it be the port number?
 

JohnH

C# Forum Moderator
Staff member
Joined
Apr 23, 2011
Messages
823
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
 

Riyaaz

New member
Joined
Oct 14, 2014
Messages
4
Programming Experience
Beginner
That's the exact error. It works perfectly on my home pc but gives this error on the univeristy pc
 
Top Bottom