当我使用gmail smtp获得异常时,我遇到了一个问题。
1) 允许不太安全的应用:打开
2)尝试过的端口587, 465, 25(相同的例外)
3)尝试禁用SSL(相同的例外)
4) smtp的telnet。gmail。用于端口465、587的com,以及从用于smtp的电子邮件地址直接发送
思想?
public async Task SendEmail(string subject, string message)
{
MailAddress fromAddress = new MailAddress("user_from@gmail.com");
MailAddress toAddress = new MailAddress("user_to@gmail.com");
MailMessage mail = new MailMessage(fromAddress.Address, toAddress.Address);
mail.Subject = subject;
mail.Body = message;
SmtpClient client = new SmtpClient();
client.Host = "smtp.gmail.com";
client.Port = 587;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.EnableSsl = true;
client.Timeout = 20000;
client.UseDefaultCredentials = false;
client.Credentials = new NetworkCredential("user_from@gmail.com", "password");
try
{
client.Send(mail);
}
catch (Exception ex)
{
Console.Write(ex.Message);
}
}
使用端口587的异常:
{System.Net.Mail.SmtpException: The operation has timed out.
at System.Net.Mail.SmtpClient.Send(MailMessage message)
at EmailsUtilities.<SendEmail>d__1.MoveNext() in client.Send(mail);
使用端口465的异常:
{System.Net.Mail.SmtpException: Failure sending mail. --->
System.IO.IOException: Unable to read data from the transport connection: The
connection was closed.
at System.Net.Mail.SmtpReplyReaderFactory.ProcessRead(Byte[] buffer, Int32
offset, Int32 read, Boolean readLine)
at System.Net.Mail.SmtpReplyReaderFactory.ReadLines(SmtpReplyReader
caller, Boolean oneLine)
at System.Net.Mail.SmtpReplyReaderFactory.ReadLine(SmtpReplyReader caller)
at System.Net.Mail.SmtpConnection.GetConnection(String host, Int32 port)
at System.Net.Mail.SmtpTransport.GetConnection(String host, Int32 port)
at System.Net.Mail.SmtpClient.GetConnection()
at System.Net.Mail.SmtpClient.Send(MailMessage message)
--- End of inner exception stack trace ---
at System.Net.Mail.SmtpClient.Send(MailMessage message)
at EmailsUtilities.<SendEmail>d__1.MoveNext() in client.Send(mail);
更新:更改客户端后。发送(mail)
到等待客户端。SendMailAsync(mail)
获取新异常:
{System.Net.Mail.SmtpException: Syntax error, command
unrecognized. The server response was:
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at
System.Net.Mail.SmtpConnection.ConnectAndHandshakeAsyncResult.End(IAsyncResult
result)
at System.Net.Mail.SmtpTransport.EndGetConnection(IAsyncResult result)
at System.Net.Mail.SmtpClient.ConnectCallback(IAsyncResult result)
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at
System.Runtime.CompilerServices.TaskAwaiter
.HandleNonSuccessAndDebuggerNotificati
on(Task task)
at EmailsUtilities.<SendEmail>d__1.MoveNext() in client.SendMailAsync
System.Net.Mail.SmtpException
感谢任何帮助!
最后使用Mail.dll(通过NuGet安装)获得电子邮件。示例:
IMail email = Mail
.Html(@"Html with an image: <img src=""cid:lena"" />")
.AddVisual(@"c:\lena.jpeg").SetContentId("lena")
.AddAttachment(@"c:\tmp.doc").SetFileName("document.doc")
.To("to@example.com")
.From("from@example.com")
.Subject("Subject")
.Create();
using(Smtp smtp = new Smtp())
{
smtp.Connect("smtp.server.com"); // or ConnectSSL for SSL
smtp.UseBestLogin("user", "password");
smtp.SendMessage(email);
smtp.Close();
}
我正在使用C#使用SMTP和gmail服务器发送电子邮件。 下面是我用于发送电子邮件的代码。我遇到了一些错误,即。 SMTP服务器需要安全连接,或者客户端未通过身份验证。服务器响应为:需要5.5.1身份验证。 我做错了什么?我如何使用gmail发送电子邮件。
我在ASP. Net Core中工作,并尝试从gmail使用smtp客户端发送电子邮件。有以下代码,但不起作用也看过以下帖子,但不起作用http://dotnetthoughts.net/how-to-send-emails-from-aspnet-core/ 它会跟踪错误 系统NotSupportedException:SMTP服务器不支持身份验证
问题内容: 问题答案: $config = Array( ‘protocol’ => ‘smtp’, ‘smtp_host’ => 'ssl://smtp.googlemail.com’, ‘smtp_port’ => 465, ‘smtp_user’ => ‘xxx’, ‘smtp_pass’ => ‘xxx’, ‘mailtype’ => ‘html’, ‘charset’ => ‘iso-8
我正在尝试发送确认电子邮件给用户使用smtp提供的谷歌和测试在我的本地机器。我已经编写了代码并提供了设置。 这是我下面的设置 我需要我的站点在https中运行吗?我只想在我的本地机器中测试我的脚本。
我在我的网站上创建了一个联系表单,并且,为了向网站帐户发送电子邮件(contact@mywebsite.com),我正在使用gmail smtp,使用与接收邮件相同的电子邮件。 所以,用户进入我的网站,点击联系页面,填写表格:姓名,电子邮件,信息。 比我发送以下代码的电子邮件: 电子邮件将进入“我的收件箱”contact@mywwebsite.com“,我可以正常阅读邮件,但是。。。当我点击“回复
我尝试从这个问题设置服务器PHP Ubuntu使用gmail表单发送电子邮件localhost。所以我设置了(帐户)从: /etc/MSMTPC: 现在,当我尝试发送测试电子邮件(以root用户身份执行)时: 给出: 所以日志上写着<代码>