使用asp.net从gmail发送电子邮件 [英] email from gmail using asp.net
问题描述
public void SendHTMLMail()
{
MailMessage Msg = new MailMessage();
MailAddress fromMail = new MailAddress("xxxxx@gmail.com");
// Sender e-mail address.
Msg.From = fromMail;
// Recipient e-mail address.
Msg.To.Add(new MailAddress("xxxxxxxx@gmail.com"));
// Subject of e-mail
Msg.Subject = "Send Gridivew in EMail";
Msg.Body += "Please check below data <br /><br />";
Msg.Body += GetGridviewData(gvUserInfo);
Msg.IsBodyHtml = true;
string sSmtpServer = "";
sSmtpServer = "587";
SmtpClient a = new SmtpClient();
a.Host = sSmtpServer;
a.EnableSsl = true;
a.Send(Msg);
}
如果我执行它,则显示错误....
if i execute it show error....
推荐答案
阅读: ^ ]
System.Net.Mail;
使用System.Net;
var fromAddress = new MailAddress("from@gmail.com",发件人名称");
var toAddress = new MailAddress("to@yahoo.com","To Name");
const string fromPassword ="password";
const string subject ="test";
const string body =嘿,现在!";
var smtp =新的SmtpClient
{
主机="smtp.gmail.com",
端口= 587,
EnableSsl = true,
DeliveryMethod = SmtpDeliveryMethod.Network,
凭据=新的NetworkCredential(fromAddress.Address,fromPassword),
超时= 20000
};
使用(var message = new MailMessage(fromAddress,toAddress)
{
主题=主题,
身体=身体
})
{
smtp.Send(message);
}
System.Net.Mail;
using System.Net;
var fromAddress = new MailAddress("from@gmail.com", "From Name");
var toAddress = new MailAddress("to@yahoo.com", "To Name");
const string fromPassword = "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,
Credentials = new NetworkCredential(fromAddress.Address, fromPassword),
Timeout = 20000
};
using (var message = new MailMessage(fromAddress, toAddress)
{
Subject = subject,
Body = body
})
{
smtp.Send(message);
}
试试这个代码
问候
假
:)
try this code
Regard
Sham
:)
这篇关于使用asp.net从gmail发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!