我正在尝试将电子邮件作为文本发送给最终用户手机,代码运行正常,但我似乎无法收到短信。
这是我的代码
public Task SendAsync()
{
var fromAddress = new MailAddress("test@gmail.com", "Authenticator");
var toAddress = new MailAddress("mynumber@sms.sancharnet.in", "User");
const string fromPassword = "mypassword";
const string subject = "subject";
string body = Session["PIN"].ToString();
var smtp = new SmtpClient
{
Host = "smtp.gmail.com",
Port = 587,
EnableSsl = true,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Credentials = new NetworkCredential(fromAddress.Address, fromPassword)
};
using (var message = new MailMessage(fromAddress, toAddress)
{
Subject = subject,
Body = body,
IsBodyHtml = false
})
{
smtp.Send(message);
}
return Task.FromResult(0);
}
我在这里缺少什么吗?或者这不是我们尝试通过电子邮件发送文本的方式吗?