1

Can't understand why this code is not working. error message is The operation has timed out

SmtpClient client = new SmtpClient("smtp.ipage.com", 465);
client.EnableSsl = true;

client.Timeout = 50000;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.Credentials = new NetworkCredential(email, password);
MailMessage msg = new MailMessage();
msg.To.Add(txtTo.Text.Trim());
msg.From = new MailAddress(email);
msg.Subject = txtSubject.Text.Trim();
msg.Body = txtMsg.Text.Trim();
//txtAttachment.Text = fileName.ToString();
Attachment attachment = new Attachment(txtAttachment.Text);
msg.Attachments.Add(attachment);
client.Send(msg);
MessageBox.Show("Successfuly sent Message.");
clear();
Yuval Itzchakov
  • 146,575
  • 32
  • 257
  • 321

1 Answers1

0

You may be getting a Null Reference Exception when adding the "To" email address. You may need to initialize the "To" MailAddressCollection.

msg.To = new MailAddressCollection();
msg.To.Add(txtTo.Text.Trim());

aslo there is some useful info here on stackoverflow about sending SmtpClient.EnableSSL = true messages using certain ports.

Community
  • 1
  • 1
Russell Jonakin
  • 1,716
  • 17
  • 18