嗨,我在尝试设置发送电子邮件时卡住并不断出错。
这是我的 using.system:
using System.Net;
using System.Web;
using System.Net.Mail;
然后我在我的发送电子邮件按钮中有这个代码。
private void BtnEmail_Click(object sender, EventArgs e)
{
try
{
string to = "myEmail@gmail.com";
string from = "myEmail@gmail.com";
string subject = "Test email";
string body = @"This is a test email";
MailMessage mail = new MailMessage(from, to, subject, body);
SmtpClient client = new SmtpClient("smtp.gmail.com");
client.Credentials = new NetworkCredential ("myEmail@gmail.com", "myPassword");
client.Port = 587;
client.EnableSsl = true;
client.Send(mail);
MessageBox.Show("Mail Sent", "Success", MessageBoxButtons.OK);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message + "\n\n" + ex.GetType().ToString() + "\n\n" + ex.StackTrace, "Exception");
}
}
看起来异常正在通过“client.send(mail);” 线。
捕获异常消息是:发送邮件失败.. System.Net.Mail.SmtpException。
知道这里出了什么问题吗?谢谢。