我想用C#發送一封電子郵件,而且我遇到了一些問題。每當我嘗試發送電子郵件時,都會收到一條消息「錯誤:無法發送郵件」。 這裏是我的代碼:C#發送電子郵件問題
try
{
client.Host = "smtp.gmail.com";
client.Port = 465;
client.UseDefaultCredentials = false;
client.Credentials = smtpCreds;
client.EnableSsl = true;
MailAddress sendFrom = new MailAddress("[email protected]");
MailAddress sendTo = new MailAddress("[email protected]");
MailMessage msg = new MailMessage(sendFrom,sendTo);
msg.Subject = "Subject";
msg.Body = "Body";
client.Send(msg);
}
catch (Exception e)
{
MessageBox.Show("Error:" + e.Message);
}
我也有這樣的聲明:
public SmtpClient client = new SmtpClient();
public System.Net.NetworkCredential smtpCreds = new System.Net.NetworkCredential("mail", "password");
希望你能幫助我。
您是否嘗試過使用'端口= 587' – Sachin
哪裏是通行證? – KF2
@Sachin我有。仍然不起作用 – Stormel