- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 gmail smtp 发送邮件:主机:smtp.gmail.com端口:587
在 MVC 应用程序中使用 gmail smtp 发送邮件时出现异常。以下代码用于发送邮件:
public static int SendMail(string StrFromAdd, string StrEmailTo, string StrSubject, string StrContents,
string SMTPServer, int SMTPPort, string SMTPUserName, string SMTPPassword,
string attachment = "", string CC = "", string BCC = "")
{
try
{
AlternateView AV = null;
System.Net.Mail.SmtpClient smtpClient = new System.Net.Mail.SmtpClient();
System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
System.Net.Mail.MailAddress fromAddress = new System.Net.Mail.MailAddress(StrFromAdd, "Test");
smtpClient.Host = SMTPServer;
smtpClient.Port = SMTPPort;
smtpClient.Credentials = new System.Net.NetworkCredential(SMTPUserName, SMTPPassword);
smtpClient.EnableSsl = true;
message.From = fromAddress;
if (attachment != null)
{
string[] attachmentsarr = attachment.Split(';');
foreach (string attach in attachmentsarr)
{
if (attach != "")
message.Attachments.Add(new Attachment(attach));
}
}
string pattern = @"^((([\w]+\.[\w]+)+)|([\w]+))@(([\w]+\.)+)([A-Za-z]{1,3})$";
if (StrEmailTo != "")
{
if (StrEmailTo.IndexOf(',') > -1)
{
string[] _strArrstrEmailTo = StrEmailTo.Split(',');
foreach (object objBCCEmailID in _strArrstrEmailTo)
if (Regex.IsMatch(objBCCEmailID.ToString().Trim(), pattern))
message.To.Add(new System.Net.Mail.MailAddress(objBCCEmailID.ToString().Trim()));
}
else
message.To.Add(new System.Net.Mail.MailAddress(StrEmailTo.ToString().Trim()));
}
if (CC != "")
{
if (CC.IndexOf(',') > -1)
{
string[] _strArrstrEmailCC = CC.Split(',');
foreach (object objBCCEmailID in _strArrstrEmailCC)
if (Regex.IsMatch(objBCCEmailID.ToString().Trim(), pattern))
message.CC.Add(new System.Net.Mail.MailAddress(objBCCEmailID.ToString().Trim()));
}
else
message.CC.Add(new System.Net.Mail.MailAddress(CC.ToString().Trim()));
}
if (BCC != "")
{
if (BCC.IndexOf(',') > -1)
{
string[] _strArrstrEmailBCC = BCC.Split(',');
foreach (object objBCCEmailID in _strArrstrEmailBCC)
if (Regex.IsMatch(objBCCEmailID.ToString().Trim(), pattern))
message.Bcc.Add(new System.Net.Mail.MailAddress(objBCCEmailID.ToString().Trim()));
}
else
message.Bcc.Add(new System.Net.Mail.MailAddress(BCC.ToString().Trim()));
}
// This is added for custom form & email template image
List<string> ImageFiles = Common.GetImagesInHTMLString(StrContents);
if (ImageFiles != null && ImageFiles.Count > 0)
{
string addStrContents = string.Empty;
for (int i = 0; i < ImageFiles.Count; i++)
{
// this is for custom form
if (ImageFiles[i].Contains("CustomFormImage"))
{
string Path = Regex.Match(ImageFiles[i], "<img.+?src=[\"'](.+?)[\"'].+?>", RegexOptions.IgnoreCase).Groups[1].Value;
int pos = Path.LastIndexOf("\\") + 1;
string FullPath = HttpContext.Current.Server.MapPath("~/img/CustomFormImage/" + Path.Substring(pos, Path.Length - pos));
if (System.IO.File.Exists(FullPath))
{
//addStrContents = addStrContents + "<img style='width:100px;height:100px;' src=\"cid:" + Path.Substring(pos, Path.Length - pos).Split('.')[0] + "\">" + Environment.NewLine;
StrContents = StrContents.Replace(Path, "cid:" + Path.Substring(pos, Path.Length - pos).Split('.')[0]);
}
}
// this is for email template image
else if (ImageFiles[i].Contains("EmailHeaderFooterImgs"))
{
string Path = Regex.Match(ImageFiles[i], "<img.+?src =[\"'](.+?)[\"'].+?>", RegexOptions.IgnoreCase).Groups[1].Value;
int pos = Path.LastIndexOf("\\") + 1;
if (System.IO.File.Exists(Path))
{
//addStrContents = addStrContents + "<img style='width:100px;height:100px;' src=\"cid:" + Path.Substring(pos, Path.Length - pos).Split('.')[0] + "\">" + Environment.NewLine;
StrContents = StrContents.Replace(Path, "cid:" + Path.Substring(pos, Path.Length - pos).Split('.')[0]);
}
}
}
AV = AlternateView.CreateAlternateViewFromString(StrContents, null, MediaTypeNames.Text.Html);
for (int i = 0; i < ImageFiles.Count; i++)
{
// this is for custom form
if (ImageFiles[i].Contains("CustomFormImage"))
{
string Path = Regex.Match(ImageFiles[i], "<img.+?src=[\"'](.+?)[\"'].+?>", RegexOptions.IgnoreCase).Groups[1].Value;
int pos = Path.LastIndexOf("\\") + 1;
string FullPath = HttpContext.Current.Server.MapPath("~/img/CustomFormImage/" + Path.Substring(pos, Path.Length - pos));
if (System.IO.File.Exists(FullPath))
{
//FileStream fs = new FileStream(FullPath, FileMode.Open, FileAccess.Read);
//Attachment a = new Attachment(fs, Path.Substring(pos, Path.Length - pos), MediaTypeNames.Application.Octet);
//message.Attachments.Add(a);
//addStrContents = addStrContents + "<img src=\"cid:" + Path.Substring(pos, Path.Length - pos).Split('.')[0] + "\">" + Environment.NewLine;
LinkedResource Img = new LinkedResource(FullPath, MediaTypeNames.Image.Jpeg);
Img.ContentId = Path.Substring(pos, Path.Length - pos).Split('.')[0];
AV.LinkedResources.Add(Img);
}
}
// this is for email template image
else if (ImageFiles[i].Contains("EmailHeaderFooterImgs"))
{
string Path = Regex.Match(ImageFiles[i], "<img.+?src =[\"'](.+?)[\"'].+?>", RegexOptions.IgnoreCase).Groups[1].Value;
int pos = Path.LastIndexOf("\\") + 1;
if (HttpContext.Current != null)
{
string FullPath = HttpContext.Current.Server.MapPath("~/EmailHeaderFooterImgs/" + Path.Substring(pos, Path.Length - pos));
if (System.IO.File.Exists(Path))
{
LinkedResource Img = new LinkedResource(Path, MediaTypeNames.Image.Jpeg);
Img.ContentId = Path.Substring(pos, Path.Length - pos).Split('.')[0];
AV.LinkedResources.Add(Img);
}
}
}
}
}
message.Subject = StrSubject;
message.IsBodyHtml = true;
if (AV != null)
message.AlternateViews.Add(AV);
else
message.Body = StrContents;
smtpClient.Send(message);
message.Dispose();
return 1;
}
catch (Exception ex)
{
}
}
下面是堆栈轨迹:
System.Security.Authentication.AuthenticationException: A call to SSPI failed, see inner exception. System.ComponentModel.Win32Exception: The function requested is not supported
at System.Net.Security.SslState.StartSendAuthResetSignal(ProtocolToken message, AsyncProtocolRequest asyncRequest, Exception exception)
at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.ForceAuthentication(Boolean receiveFirst, Byte[] buffer, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResult lazyResult)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Net.TlsStream.ProcessAuthentication(LazyAsyncResult result)
at System.Net.TlsStream.Write(Byte[] buffer, Int32 offset, Int32 size)
at System.Net.Mail.SmtpConnection.Flush()
at System.Net.Mail.ReadLinesCommand.Send(SmtpConnection conn)
at System.Net.Mail.EHelloCommand.Send(SmtpConnection conn, String domain)
at System.Net.Mail.SmtpConnection.GetConnection(ServicePoint servicePoint)
at System.Net.Mail.SmtpClient.GetConnection()
at System.Net.Mail.SmtpClient.Send(MailMessage message)
at MVC.Common.SendMails.SendMail(String StrFromAdd, String StrEmailTo, String StrSubject, String StrContents, String SMTPServer, Int32 SMTPPort, String SMTPUserName, String SMTPPassword, String attachment, String CC, String BCC) in SendMails.cs:line 296
注意:相同的代码在托管在同一服务器上的另一个应用程序中运行,也使用相同的 gmail 配置来发送邮件。
最佳答案
假设您的代码是为(例如).NET Framework 4.7.2 编译的,那么请确保您的 Web.config
包括:
<httpRuntime targetFramework="4.7.2" />
如果您的 targetFramework
设置太低或缺失,则编译后的代码将自动尝试请求 TLS 1.2(发生在 .NET Framework 4.7 以上),但目标运行时将不支持它,因此出现错误。
(归功于 this SO answer,这让我意识到这里出了什么问题——尽管那个问题和这个问题并不重复。)
关于c# - GMAIL SMTP : A call to SSPI failed exception - The function requested is not supported,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54648298/
只是出于好奇,我想知道gmail是如何做到的。查看页面源代码后,您看不到任何链接、onclick 方法和 javascript。我知道他们隐藏了 javascript,但页面仍然知道有点击。是否有一个
最近谷歌宣布,出于安全目的,Gmail 将使用代理加载外部图像。这导致我的应用程序在 Gmail 中显示图像时出现问题。 Gmail图片元素检查: https://ci5.googleusercont
我想将节点脚本作为 cronjob 运行,它使用 Gmail 的 API 来轮询我拥有的 gmail 帐户。 我关注 these quickstart instructions : 我被困在第一步。在
如果您在 Gmail 上处于非事件状态,则通过一段时间不移动鼠标,您的聊天状态会更改为橙色,这意味着空闲。但是当您再次开始移动鼠标时,它会变回绿色,表示处于事件状态。它如何知道您何时移动鼠标? 最佳答
您知道,当您加载 GMail 时,左侧会显示“撰写邮件”、“收件箱”、“已发送邮件”等吗?我在页面源代码中搜索了“撰写邮件”,但一无所获。 最佳答案 Gmail 界面使用 JavaScript 动态加
我正在创建一个函数,使用 Google 的 API 从一个人的 gmail 帐户导入联系人。但是我知道许多企业注册 Google 是为了拥有更专业的域名(例如 some_name@bislr.com)
我可以通过桌面应用程序使用 Gmail API 成功读取我的收件箱内容。但是,当我尝试阅读其他人的 gmail 收件箱时,我收到 Delegation denied 异常? 所以我的问题是,Gmail
我已经读到我可以使用 gmail atom 提要从谷歌创建的“内置”标签中获取邮件。 但是当我尝试从“已读”标签获取邮件时,使用 https://mail.google.com/mail/feed/a
通过 Gmail API 发送到 Gmail 地址的邮件在 Gmail 中被标记为“小心处理此邮件。它包含通常用于窃取个人信息的内容。” 该消息基本上只是说测试。并且通过 Gmail SMTP 发送的
编辑 :解决下面的第一条评论,为清楚起见,这不是代码问题。问题很简单: 我应该在新 Gmail UI 的 URI 查询字符串中输入什么来查看 Gmail API 创建的草稿邮件? 尽管这并不是一个真正
我是谷歌产品的新手。我打算开始在 gmail 中添加一些东西。使用类似于 Add on 的 Add on 或 chrome Gmail Extension 更好吗?如果是add-on,我们不能直接在s
使用标准查询格式时,Gmail api 和 Gmail Web ui 的结果有所不同,如下所述 - https://support.google.com/mail/answer/7190 . 该问题专
我正在尝试创建一个 PHP 应用程序,它将自动设置用户的电子邮件签名。这部分有效,我可以为用户设置签名。 我的问题是我在 SendAs 设置中找不到任何选项,该选项将禁用 GMail 中签名前插入的两
我的电子邮件标记通过了电子邮件标记测试器,我尝试了 JSON-LD 和微数据,但无论如何 - 我只是看不到标记在 Gmail (iOS) 客户端中的任何效果。 即使是 Google 自己文档中的基本示
我目前正在使用 Gmail 实验室功能 - canned responses.我有很多这样的预设回复并使用 their menu找到合适的,证明是耗时的。通过以下方式找到预设响应会更容易: 将预设回复
请问是否可以在我的 Gmail 状态中发布倒计时? 像“01:44:15:23”及其不断递减。 最佳答案 发现一个好 article to share : Google Talk 使用 XMPP 那么
我开发了一个上下文小工具并将其安装在我的域中。它在我的域中运行良好,但在我的域之外无法正常工作。如何在我的域外访问我的小工具? 最佳答案 您指的是您的 Google Apps 域吗?根据 Google
我在 this guide 之后配置了推送通知并在调用 watch 时端点我得到大约一周的到期时间。 在此期间,我希望收到有关我已配置的 Pub/Sub 主题的通知,而无需调用 watch。在到期日期
是否有可以在 gmail 中捕获的 API 或事件,以便我可以启动工作流甚至触发 python 脚本。 我正在尝试自动化一项工作,该工作将从已到达 gmail 的电子邮件中提取 csv 附件。然后它会
为什么网络版的 Gmail 会在不使用 = 标记中断位置的情况下对邮件内容进行换行,这使得电子邮件处理变得非常困难: 查看gmail发送的原始邮件内容: 这封由 Mac OS X Mail 发送的邮件
我是一名优秀的程序员,十分优秀!