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");
}
}
 
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);
            }
 
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
 
Exact | Define Exact at Dictionary.com

Based on internet research I think the exact exception message is "Message could not be sent." and that is thrown as SmtpException, which means you have to investigate all its inner exceptions to get the full error condition, as described in my previous post.
 
I have to tell gmail to let me run my Python emailer.


jpg.gif
 

Attachments

  • email.jpg
    email.jpg
    60.1 KB · Views: 80
Back
Top Bottom