我的邮件发件人代码最近因gmail而失败

时间:2014-08-07 17:19:19

标签: c# smtp gmail

我用这段代码用gmail发送邮件!在它运作良好之前,但现在它失败了! (它在c#和表单应用程序中)

cmdSend.Text = "Wait!";
cmdSend.Enabled = false;
SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
var mail = new MailMessage();
mail.From = new MailAddress(txtMailAddressFrom.Text);
mail.To.Add(txtMailAddressTo.Text);
mail.Subject = txtSubject.Text;
mail.IsBodyHtml = true;
string htmlBody;
htmlBody = txtMailBody.Text;
mail.Body = htmlBody;
SmtpServer.Port = 578;
SmtpServer.UseDefaultCredentials = false;
SmtpServer.Credentials = new System.Net.NetworkCredential(txtMailAddressFrom.Text, txtPassword.Text);
SmtpServer.EnableSsl = true;
SmtpServer.Send(mail);
SmtpServer.Dispose();
cmdSend.Text = "Send";
cmdSend.Enabled = true;

我使用端口465测试但是没有工作!

1 个答案:

答案 0 :(得分:0)

Gmail不使用端口587而不使用578吗?