通过 gmail 发送 Asp.Net 电子邮件
我正在尝试使用下面的代码和配置从 ASP.Net 通过 GMail 发送电子邮件。不幸的是,它似乎不起作用,也没有抛出错误消息。服务器日志或邮件 IIS 邮件文件夹中没有任何内容,我什至检查了发件人地址的垃圾箱,看看邮件是否最终到达那里。任何帮助将不胜感激。
C# 部分
public void SendFeedback()
{
string emailFrom = this.Email.Text;
MailMessage message = new MailMessage();
// here is an important part:
message.From = new MailAddress(emailFrom, "Mailer");
// it's superfluous part here since from address is defined in .config file
// in my example. But since you don't use .config file, you will need it.
message.Subject = "www.gumpshen.com - Website Query";
message.IsBodyHtml = true;
message.Body = string.Format(" Name = {0}, Phone = {1}", Name.Text, Phone.Text);
message.Body += Environment.NewLine;
message.Body += Environment.NewLine;
message.Body += ProjectDetails.Text; ;
var client = new SmtpClient();
try
{
client.Send(message);
这是配置部分:
<system.net>
<mailSettings>
<smtp from="[email protected]" deliveryMethod="Network" >
<network host="smtp.gmail.com" port="587"
userName="[email protected]" password="myPassword"/>
</smtp>
</mailSettings>
</system.net>
I am trying to send an email via GMail from ASP.Net using the code and config below. Unfortunatly it doesn't seem to be working and it also isn't throwing an error message. There is nothing in the server logs or the mail IIS mail folders, I even checked the trash of the from address to see if the mail ended up there. Any help would be really appreciated.
C# Section
public void SendFeedback()
{
string emailFrom = this.Email.Text;
MailMessage message = new MailMessage();
// here is an important part:
message.From = new MailAddress(emailFrom, "Mailer");
// it's superfluous part here since from address is defined in .config file
// in my example. But since you don't use .config file, you will need it.
message.Subject = "www.gumpshen.com - Website Query";
message.IsBodyHtml = true;
message.Body = string.Format(" Name = {0}, Phone = {1}", Name.Text, Phone.Text);
message.Body += Environment.NewLine;
message.Body += Environment.NewLine;
message.Body += ProjectDetails.Text; ;
var client = new SmtpClient();
try
{
client.Send(message);
This is the Config section:
<system.net>
<mailSettings>
<smtp from="[email protected]" deliveryMethod="Network" >
<network host="smtp.gmail.com" port="587"
userName="[email protected]" password="myPassword"/>
</smtp>
</mailSettings>
</system.net>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要
client.EnableSsl=true;
检查此站点的代码:通过 Gmail 发送电子邮件
You need
client.EnableSsl=true;
Check the code from this site: Email via Gmail