我在此代码中遇到问题我是新来的请帮帮我
错误是: Failure sending mail.
内部异常是: Unable to connect to the remote server.
这是我的代码:
try
{
MailMessage message = new MailMessage();
SmtpClient smtp = new SmtpClient();
message.To.Add(emaild_id);
message.From = new MailAddress(my_email_id);
message.Subject = "Info";
message.Body = "something.....";
smtp.Port = 587;
smtp.Host = "smtp.gmail.com";
smtp.EnableSsl = true;
smtp.UseDefaultCredentials = false;
smtp.Credentials = new NetworkCredential(strFromMail, strPassword);
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.Send(message);
MessageBox.Show("Mail has been sent successfully.");
}
catch (Exception ErrMessage)
{
MessageBox.Show(ErrMessage.Message, "ASCEND", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
答案 0 :(得分:0)
尝试使用端口号465而不是587