我已經在codebehind aspx頁面中寫下面的代碼發送email.I想使用谷歌smtp服務器。但一些如何我無法接收的電子郵件使用asp.net和谷歌smtp服務器發送電子郵件
protected void btnSubmit_Click(object sender, EventArgs e)
{
// Sender e-mail address.
MailAddress From = new MailAddress(txtFrom.Text);
// Recipient e-mail address.
MailAddress To = new MailAddress(txtTo.Text);
MailMessage Msg = new MailMessage(From,To);
Msg.Subject = txtSubject.Text;
Msg.Body = txtBody.Text;
// your remote SMTP server IP.
SmtpClient client = new SmtpClient("smtp.gmail.com");
client.Credentials = new System.Net.NetworkCredential
("*******@gmail.com", "**********");
client.EnableSsl = true;
client.Port = 465;
client.Send(Msg);
client.Dispose();
}
錯了我在做什麼?請幫助
我認爲港gmail是587而不是465,請嘗試將其更改爲: client.Port = 587; –