我知道有很多關於此問題的問題和解答,我確實閱讀了allot,但它似乎全部過時。通過gmail發送郵件
因此,我有一個移動應用程序,它將使用註冊到雲服務,然後向用戶的電子郵件地址發送歡迎電子郵件。
該服務部在C#WCF女巫做也將郵件發送
下面是用於測試郵件原型功能:
static void SendMail()
{
var fromAddress = new MailAddress("gmail account", "App name");
var toAddress = new MailAddress("User email", "User account");
const string fromPassword = "gmail password";
const string subject = "test";
const string body = "Hey now!!";
var smtp = new SmtpClient
{
Host = "smtp.gmail.com",
Port = 587,
EnableSsl = true,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Credentials = new NetworkCredential(fromAddress.Address, fromPassword),
Timeout = 20000
};
using (var message = new MailMessage(fromAddress, toAddress)
{
Subject = subject,
Body = body
})
{
smtp.Send(message);
}
Console.WriteLine("Sent");
Console.ReadLine();
}
使用我的代碼全部由別人建議的事情。但我仍然得到錯誤信息
An unhandled exception of type 'System.Net.Mail.SmtpException' occurred in System.dll
Additional information: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at
嘗試加入'{如果(String.IsNullOrEmpty(Sendmail的) ) return; }。對你的函數。我不知道,但 – BNN 2014-12-08 09:25:43
沒有改變我得到'smtp.Send(消息)'行中的錯誤' – Jester 2014-12-08 09:28:01
錯誤是什麼? – BNN 2014-12-08 09:32:11