我没有依赖我的主机发送电子邮件,而是考虑使用我的Gmail帐户发送电子邮件.这些电子邮件是我在节目中播放的乐队的个性化电子邮件.有可能吗?
出于某种原因," 通过Gmail发送.NET中的电子邮件 "既没有被接受的答案也没有其他任何一个对我有用.他们为什么不工作?
更新:我在另一个问题中尝试了所有答案(接受和否则),但没有一个能够奏效.
我想知道它是否适用于其他任何人,否则谷歌可能已经改变了一些事情(之前发生过).
当我尝试使用的代码片段时SmtpDeliveryMethod.Network,我会在Send(消息)上快速收到SmtpException.信息是
SMTP服务器需要安全连接或客户端未经过身份验证.
服务器响应是:
5.5.1需要验证.了解更多"< - 认真,它在那里结束.
更新:
这是我很久以前问过的一个问题,接受的答案是我在不同的项目中使用了很多次的代码.
我已经在这篇文章和其他EmailSender项目中采用了一些想法,在Codeplex上创建了一个EmailSender项目.它专为可测试性而设计,支持我最喜欢的SMTP服务,如GoDaddy和Gmail.
我想从我的应用程序发送一封电子邮件,我写了以下代码来发送邮件
MailMessage msg = new MailMessage();
msg.From = new MailAddress("mymailid");
msg.To.Add("receipientid");
msg.Subject = "test";
msg.Body = "Test Content";
msg.Priority = MailPriority.High;
SmtpClient client = new SmtpClient();
client.Credentials = new NetworkCredential("mymailid", "mypassword", "smtp.gmail.com");
client.Host = "smtp.gmail.com";
client.Port = 587;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.EnableSsl = true;
client.UseDefaultCredentials = true;
client.Send(msg);
Run Code Online (Sandbox Code Playgroud)
我在localhost上运行它,所以我正在做什么错误发送它.
当我发送按钮时,它给出了一个错误
SMTP服务器需要安全连接或客户端未经过身份验证.服务器响应为:5.5.1需要身份验证.
Web.config文件中的代码
<appSettings>
<add key="webpages:Version" value="2.0.0.0" />
<add key="webpages:Enabled" value="false" />
<add key="PreserveLoginUrl" value="true" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
<add key="smtpServer" value="smtp.gmail.com" />
<add key="EnableSsl" value …Run Code Online (Sandbox Code Playgroud) 为了更好地保护您的用户,GMail和其他邮件提供商建议将我们的所有应用程序升级到OAuth 2.0.
我是对的,这意味着System.Net.Mail不再工作,我们需要使用另一个库MailKit吗?
一般来说,我试图了解如何发送电子邮件而不允许"访问不太安全的应用程序"?
因为我有System.Net.Mail.SmtpException: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required.当smtpClient.Send(message);执行.
如果解决这个问题的唯一方法是使用MailKit,我认为这个问题将是一个很好的实用的逐步切换教程从System.Net.Mail使用MailKit和Google.Apis.Auth.OAuth2.我不知道可能会使用一般解决方案DotNetOpenAuth吗?
我的应用程序中有以下类,对应于向任何地址(gmail,yandex和其他人)发送电子邮件:
public class EmailSender
{
public void SendEmail(SmtpServerSettings serverSettings, SendEmailRequest emailRequest)
{
// Usually I have 587 port, SmtpServerName = smtp.gmail.com
_logger.Trace("Sending message with subject '{0}' using SMTP server {1}:{2}",
emailRequest.Subject,
serverSettings.SmtpServerName,
serverSettings.SmtpPort);
try
{
using …Run Code Online (Sandbox Code Playgroud) 我使用以下代码尝试异步发送电子邮件,但没有发送电子邮件,我不确定是什么做错了.我还在web.config中为电子邮件协议添加了第二段代码.
SendEmailAsync代码
await UserManager.SendEmailAsync(username.Id, "MTSS-B: Forgot Password", "Here is your new password. Please go back to the MTSS-B web tool and sign in. You will be prompted to create your own password.<br/><br/>" + tmpPass + "<br/><br/>MTSS-B Administrator");
Run Code Online (Sandbox Code Playgroud)
Web.config代码
<system.net>
<mailSettings>
<smtp>
<network host="smtp1.airws.org" userName="" password="" />
</smtp>
</mailSettings>
</system.net>
Run Code Online (Sandbox Code Playgroud)
********更新
我测试了是否可以使用常规方法发送电子邮件,并且可以使用以下代码发送电子邮件.
MailMessage m = new MailMessage(new MailAddress(ConfigurationManager.AppSettings["SupportEmailAddr"]), new MailAddress(model.Email));
m.Subject = "MTSS-B: Forgot Password";
m.Body = string.Format("Here is your new password. Please go back to the MTSS-B web tool and …Run Code Online (Sandbox Code Playgroud) 我在Exchange Online服务上有一个邮件帐户.现在我正在尝试测试我是否能够通过c#应用程序向客户(在varoius域和Microsoft Office 365上)发送邮件
我尝试实现以下代码,但我收到错误
"根据验证程序,远程证书无效."
MailMessage mail = null;
mail = new MailMessage();
string[] strToList = "abc@gmail.com"
foreach (string strID in strToList)
{
if (strID != null)
{
mail.To.Add(new MailAddress(strID));
}
}
mail.From = "demo@onmicrosoft.com";
mail.Subject = "testing"
mail.IsBodyHtml = true;
mail.Body = "mail body";
SmtpClient client = new SmtpClient("smtp.outlook.office365.com");
client.Port = 587;
client.EnableSsl = true;
client.UseDefaultCredentials = false;
NetworkCredential cred = new System.Net.NetworkCredential("demo@onmicrosoft.com", "mypassword");
client.Credentials = cred;
client.Send(mail);
Run Code Online (Sandbox Code Playgroud)
如果我做错了,请建议.非常感谢提前.
我有一个 winform 应用程序在我们的生产车间运行,它发送电子邮件进行报告,所以从昨天开始它无法发送电子邮件,我收到了这条消息
\n“SMTP 服务器需要安全连接,或者客户端未经过身份验证。服务器响应为:5.7.0 需要身份验证。”
\n我检查了这篇文章\n SMTP 服务器需要安全连接或客户端未经过身份验证。服务器响应为: 5.5.1 需要身份验证?
\n我发现谷歌不再支持第三方应用程序,它不允许安全性较低的应用程序\n这是来自谷歌安全性较低的应用程序\n安全性较低的应用程序访问:
\n某些应用程序和设备使用安全性较低的登录技术,这会使您的帐户容易受到攻击。您可以关闭对这些应用程序的访问权限(我们建议这样做),或者如果您想尽管存在风险但仍想使用它们,则可以将其打开。如果不使用\xe2\x80\x99,Google 将自动关闭此设置。\n此设置不再可用。了解更多
\n所以我尝试添加 SmtpServer.UseDefaultCredentials = false; 但没有任何作用,我认为问题是谷歌不再支持第三方访问电子邮件。\n这是我的代码
\ntry\n{\n MailMessage mail = new MailMessage();\n System.Net.Mail.SmtpClient SmtpServer =\n new System.Net.Mail.SmtpClient("smtp.gmail.com");\n string sender = "user@gmail.com";\n mail.From = new MailAddress(sender);\n mail.To.Add("receiver@plastikon.com");\n mail.Priority = MailPriority.High;\n mail.Subject = subject;\n mail.IsBodyHtml = true;\n mail.Body = ($"{body} \\n Name of computer: { HostName} ");\n\n SmtpServer.Port = 587;\n SmtpServer.Credentials = new \n System.Net.NetworkCredential("user@gmail.com", "Password");\n SmtpServer.EnableSsl = true;\n SmtpServer.UseDefaultCredentials = false;\n\n SmtpServer.Send(mail);\n}\n …Run Code Online (Sandbox Code Playgroud) 这是与我的问题类似的相关主题,答案是正确的:
gmail-error-the-smtp-server-requires-a-secure-connection-or-the-client-was-not
这是相关网站:
send-email-from-gmail-with-smtp-authentication-but-got-5_5_1-authentication-required-error
我使用 c# 发送邮件 & 我的代码是正确的 & 在本地 & 旧主机上工作。
问题是关于我没有远程访问权限的新主机。
在新主机中,我收到了来自谷歌的这封电子邮件:

我点击Check activity并点击it was me。
但问题仍然存在。
我没有对新主机的远程访问权限,我不想将密码提供给他们。
这是来自新主机的错误:
发送电子邮件失败,SmtpException -> 错误:System.Net.Mail.SmtpException:SMTP 服务器需要安全连接或客户端未通过身份验证。服务器响应为:5.7.0 Authentication Required。在 System.Net.Net.Mail.MailCommand.Send(SmtpConnection conn, Byte[] command, MailAddress from, Boolean allowUnicode) 处的 System.Net.Mail.MailCommand.CheckResponse(SmtpStatusCode statusCode, String response) 处了解更多信息。 Mail.SmtpTransport.SendMail(MailAddress 发件人、MailAddressCollection 收件人、String deliveryNotify、Boolean allowUnicode、SmtpFailedRecipientException& 异常)在 Virtual_Visa_Cards.WebForm4.Send_Email_Gmail(从字符串显示字符串名称到字符串)的 System.Net.Mail.SmtpClient.Send(MailMessage 消息) , 字符串主题, 字符串 html_body, 字符串 sender_email,
什么是解决方案以及如何在 gmail 帐户中添加受信任的新主机 ip?(请考虑我的编辑)
编辑:
1. 我不想启用两因素身份验证
2. 低安全应用程序开启
3.
但是如果您无权访问生产服务器怎么办。尝试解决方案 3
情况 3 的解决方案 3:您必须为您的 google …
我正在尝试通过 Gmail 发送邮件。我在本地主机上测试时成功发送邮件,但是当我将它上传到网络主机时这不起作用。我看到这种类型的错误:
请求类型 System.Net.Mail.SmtpPermission, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 的权限失败。
每当我使用端口 25 时,都会出现以下此类错误:
SMTP 服务器需要安全连接或客户端未通过身份验证。服务器响应为:5.5.1 Authentication Required
下面是我发送电子邮件的代码。
MailMessage mail = new MailMessage("host@gmail.com","User@gamil.com");
SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
mail.Subject = "Any String"
mail.Body = mailbody;
mail.IsBodyHtml = true;
SmtpServer.Port = 587;
SmtpServer.DeliveryMethod = SmtpDeliveryMethod.Network;
SmtpServer.UseDefaultCredentials = false;
SmtpServer.Credentials = new System.Net.NetworkCredential("xyz@gmail.com","123");
SmtpServer.EnableSsl = true;
SmtpServer.Send(mail);
Run Code Online (Sandbox Code Playgroud)
有什么解决办法吗?请给我建议!
下面是我正在使用的代码。请告知如何纠正此问题。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Net;
using System.Net.Mail;
public partial class mailtest : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void SendEmail(object sender, EventArgs e)
{
lblmsg.Text = "";
try
{
using (MailMessage mm = new MailMessage(txtEmail.Text, txtTo.Text))
{
mm.Subject = txtSubject.Text;
mm.Body = txtBody.Text;
//if (fuAttachment.HasFile)
//{
// string FileName = Path.GetFileName(fuAttachment.PostedFile.FileName);
// mm.Attachments.Add(new Attachment(fuAttachment.PostedFile.InputStream, FileName));
//}
mm.IsBodyHtml = false;
SmtpClient smtp = new …Run Code Online (Sandbox Code Playgroud) 对不起,我看到很多关于此事的类似帖子,但从来没有找到任何解决我的问题,所以我决定发布它.
我使用ASP.NET c#使用gmail以编程方式发送电子邮件,代码如下.
string EmailAddress = senderemail;
MailMessage mailMessage = new MailMessage(EmailAddress, EmailAddress);
mailMessage.Subject = "This is a test email";
mailMessage.Body = "This is a test email. Please reply if you receive it.";
SmtpClient smtpClient = new SmtpClient();
smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
smtpClient.EnableSsl = true;
smtpClient.Host = "smtp.gmail.com";
smtpClient.Port = 587;
smtpClient.Credentials = new System.Net.NetworkCredential()
{
UserName = EmailAddress,
Password = senderpassword
};
smtpClient.UseDefaultCredentials = false;
smtpClient.Send(mailMessage);
Run Code Online (Sandbox Code Playgroud)
我和其他人一样收到了这个错误
错误:
SMTP服务器需要安全连接或客户端未经过身份验证.服务器响应为:5.5.1需要身份验证.了解更多信息.
GMAIL已经做了以下两项行动.
无安全的应用程序:打开
-2步验证:关闭
我不在乎这个gmail帐户是安全还是什么.我不需要此帐户的任何安全性.我该怎么办?
c# ×11
gmail ×5
smtp ×5
email ×4
.net ×3
asp.net ×2
asp.net-mvc ×1
office365 ×1
smtpclient ×1
winforms ×1