在 ASP .Net 中发送电子邮件
如何使用outlook地址在ASP .Net上发送电子邮件?
我尝试过这段代码,但没有成功:
Dim mailMessage As System.Net.Mail.MailMessage = New System.Net.Mail.MailMessage()
mailMessage.From = New System.Net.Mail.MailAddress("fromAddress")
mailMessage.To.Add(New System.Net.Mail.MailAddress("toAddress"))
mailMessage.Priority = Net.Mail.MailPriority.High
mailMessage.Subject = "Subject"
mailMessage.Body = "test"
Dim smtpClient As System.Net.Mail.SmtpClient = New System.Net.Mail.SmtpClient("xxx.outlook.com", portNumber)
smtpClient.Send(mailMessage) //--> got error here
但是当我执行代码时,它收到此错误消息:
The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.1 Client was not authenticated
我尝试添加一行代码:
smtpClient.Credentials = New System.Net.NetworkCredential(用户名,密码)
但仍然无法发送电子邮件。
有人可以帮忙吗?
How to send e-mail on ASP .Net using outlook address??
I've tried this code but no luck:
Dim mailMessage As System.Net.Mail.MailMessage = New System.Net.Mail.MailMessage()
mailMessage.From = New System.Net.Mail.MailAddress("fromAddress")
mailMessage.To.Add(New System.Net.Mail.MailAddress("toAddress"))
mailMessage.Priority = Net.Mail.MailPriority.High
mailMessage.Subject = "Subject"
mailMessage.Body = "test"
Dim smtpClient As System.Net.Mail.SmtpClient = New System.Net.Mail.SmtpClient("xxx.outlook.com", portNumber)
smtpClient.Send(mailMessage) //--> got error here
But while I'm execute the code, it got this error message:
The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.1 Client was not authenticated
I've tried to add a line of code:
smtpClient.Credentials = New System.Net.NetworkCredential(username, password)
But still can't send the e-mail.
Anyone can help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
smtpClient.UseDefaultCredentials = false;
smtpClient.EnableSsl
设置为 true / falsesmtpClient.UseDefaultCredentials = false;
before you set new CredentialssmtpClient.EnableSsl
to true / false depending on your environment我猜您正在使用 Exchange 2007 或更高版本作为后端?
无论如何,您的邮件服务器不允许您匿名发送邮件。您需要在代码中提供用户名/密码,或者允许来自网络服务器的未经身份验证的中继。
与 IT 人员讨论他们的喜好。
I'm guessing you are using Exchange 2007 or later as backend?
Anyway, your mail server does not allow you to send mails anonymously. You'll either need to supply a username/password in your code or allow unauthenticated relaying from your webserver.
Talk to your IT guys what they prefer.
我是用c#做的。这可能对你有帮助。请检查。
并在 web.config 文件中
I did it using c#.This may help you.Please check.
and in web.config file
尝试这些设置,检查
.EnableSSL
属性是否为true/false
以及您的邮件服务器
所在的smtp post number
侦听外发邮件。当您没有在 Outlook 中为 gmail Outlook 配置设置启用 SSL 设置时,它会给出相同的错误,但找到了 SSL 设置的原因。
我们尝试一下,可能会解决您的问题。
如果它不能解决您的问题,请检查您的邮件服务器/客户端的问题。
Try these settings check for
.EnableSSL
property totrue/false
and thesmtp post number
on which yourmail server
listen for outgoing mail.When you do not set enable the SSL settings in outlook for gmail outlook configuration then it gives same error but the reason was found the SSL settings..
well try this may it will solve your problem..
if it does not solve your problem then check your mail server/ client for the problem.
我使用此代码从我的 Gmail 帐户发送邮件。
I use this code to send mail from my gmail account.
遇到同样的错误,移动了 client.UseDefaultCredentials = false;在设置 client.Credentials 之前一切正常。
was having the same error, moved the client.UseDefaultCredentials = false; before setting client.Credentials and everything works.