如何使用gmail smtp从.net应用程序发送邮件,我尝试了不同的方式,但无法发送邮件。 [英] How to send mail from .net application using gmail smtp, i have tried different ways but unable to send mails.

查看:76
本文介绍了如何使用gmail smtp从.net应用程序发送邮件,我尝试了不同的方式,但无法发送邮件。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谢谢,

如何使用gmail smtp从.net应用程序发送邮件,

我尝试了不同的方式但无法发送邮件。

如果我使用来自oter smtp的gmail smtp以外的另一个smtp我们可以发送邮件。

谢谢&问候

Lakshman

9052026114



我尝试过:



使用SMTPUser =example.gmail.com,SMTPPassword =password;



//现在实例化MailMessage的新实例

MailMessage mail = new MailMessage();



//设置邮件的发件人地址

mail.From =新邮件地址(SMTPUser,AspnetO);



//设置邮件的收件人地址

mail.To.Add(ToEmail);



//设置邮件主题

mail.Subject = Subject ;



//设置邮件正文

mail.Body = Body;



//即使您没有发送HTML消息也要保持原样

mail.IsBodyHtml = true;



//将邮件的优先级设置为正常

mail.Priority = MailPriority.Normal;



//实例化a SmtpClient的新实例

SmtpClient smtp = new SmtpClient();

smtp.Port = 587; //或者您也可以使用端口#587

/

//如果您使用SSL / TLS使用安全认证,那么true否则为false
smtp.EnableSsl = true;



smtp.Send(mail);

Thank you,
How to send mail from .net application using gmail smtp,
I have tried different ways but unable to send mails.
If i use another smtp other than gmail smtp from oter smtp we are able to send mails.
Thanks & Regards
Lakshman
9052026114

What I have tried:

tring SMTPUser = "example.gmail.com", SMTPPassword = "password";

//Now instantiate a new instance of MailMessage
MailMessage mail = new MailMessage();

//set the sender address of the mail message
mail.From = new MailAddress(SMTPUser, "AspnetO");

//set the recepient addresses of the mail message
mail.To.Add(ToEmail);

//set the subject of the mail message
mail.Subject = Subject;

//set the body of the mail message
mail.Body = Body;

//leave as it is even if you are not sending HTML message
mail.IsBodyHtml = true;

//set the priority of the mail message to normal
mail.Priority = MailPriority.Normal;

//instantiate a new instance of SmtpClient
SmtpClient smtp = new SmtpClient();
smtp.Port = 587; //or you can also use port# 587
/
//if you are using secure authentication using SSL/TLS then "true" else "false"
smtp.EnableSsl = true;

smtp.Send(mail);

推荐答案

这是最常见的问题,请在发布前做基础研究。通常问题不是您的代码,而是您没有设置帐户以允许其他应用程序使用它;



用于访问帐户的安全性较低的应用程序 - 帐户帮助 [ ^ ]



或者gmail已经禁用了您的帐户,直到您手动传递验证码为止。 />


最终的解决方案是不通过gmail发送电子邮件,请参阅第6点



因此,你不应该花时间去做ASP.NET论坛 [ ^ ]
This is the most frequently asked question, please do basic research before posting. Usually the issue is not your code but the fact that you haven't set your account to allow other apps to use it;

Allowing less secure apps to access your account - Accounts Help[^]

Or gmail has disabled your account until you manually pass a captcha.

Either way the ultimate solution is to not send email through gmail, see point 6

Things you shouldn't spend time doing | The ASP.NET Forums[^]


首先需要记住的是,您应该继续为Gmail帐户中的POP设置启用邮件。

然后收集以下内容

1.接收者电子邮件地址

2.发件人电子邮件:用户ID和密码

3 。命名空间System.Net.Mail

4.电子邮件附件如果有任何

检查以下链接

使用ASP.NET从您的Gmail帐户发送电子邮件 [ ^ ]

你的邮件发送有很多东西可能会失败,例如,

有很多因素可能影响你的邮件发送代码,这里是列表,

1.防火墙阻止端口587(这是用于smtp gmail服务器的端口)

2.无法在机器上连接互联网或互联网连接在ping时遇到一些障碍

3.由于一些拼写错误,用户名和密码可能会出错

4.启用SSL是阻止电子邮件发送

5.禁用Gmail帐户中smtp服务器的POP设置
First thing you need to remember is, you should keep enable your mail for POP settings in your Gmail account.
then collect following things
1. Receiver Email address
2. Sender Email: UserID and Password
3. Namespace System.Net.Mail
4. Email Attachment if any
check below link
Send Email from your Gmail Account using ASP.NET[^]
There are many things that can failed your email sending like,
There are so many factor that may affects your email sending code, here is list,
1. Firewall block port 587 (This is port for smtp gmail server)
2. Internet connection is not available on machine or internet connection has face some obstacles while pinging
3. Due to some typo mistake UserName and password may be get wrong
4. Enable SSL is block email sending
5. POP settings for smtp server in your Gmail account is disabled


这篇关于如何使用gmail smtp从.net应用程序发送邮件,我尝试了不同的方式,但无法发送邮件。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆