public static void SendEmailToInformCustomerForNewOrderMessage()
{
try
{
SendMail();
}
catch (Exception ex)
{
Logger.Write(CreateExceptionString(ex));
}
}
public static void SendMail()
{
try
{
// Gmail Address from where you send the mail
dynamic fromAddress = "frommail@gmail.com";
// any address where the email will be sending
dynamic toAddress = "tomail@gmail.com";
//Password of your gmail address
const string fromPassword = "password";
// Passing the values and make a email formate to display
string subject = "test mail code";
string body = "From: " + "Puneet";
body += "Email: " + "fromemail@gmail.com";
body += "Subject: " + "Test email code";
body += "Question: " + "test question";
// smtp settings
dynamic smtp = new System.Net.Mail.SmtpClient();
if (true)
{
smtp.Host = "smtp.gmail.com";
smtp.Port = 587;
smtp.EnableSsl = true;
smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
smtp.Credentials = new NetworkCredential(fromAddress, fromPassword);
smtp.UseDefaultCredentials = false;
smtp.Timeout = 20000;
}
// Passing values to smtp object
dynamic message = new MailMessage(fromAddress, toAddress, subject, body);
smtp.Send(message);
}
catch (Exception ex)
{
Logger.Write(CreateExceptionString(ex));
}
}
public static string CreateExceptionString(Exception e)
{
StringBuilder sb = new StringBuilder();
CreateExceptionString(sb, e, string.Empty);
return sb.ToString();
}
private static void CreateExceptionString(StringBuilder sb, Exception e, string indent)
{
if (indent == null)
{
indent = string.Empty;
}
else if (indent.Length > 0)
{
sb.AppendFormat("{0}Inner ", indent);
}
sb.AppendFormat("Exception Found:" + "& vbLf &" + "{0}Type: {1}", indent, e.GetType().FullName);
sb.AppendFormat("& vbLf &" + "{0}Message: {1}", indent, e.Message);
sb.AppendFormat("& vbLf &" + "{0}Source: {1}", indent, e.Source);
sb.AppendFormat("& vbLf &" + "{0}Stacktrace: {1}", indent, e.StackTrace);
if (e.InnerException != null)
{
sb.Append("& vbLf &");
CreateExceptionString(sb, e.InnerException, indent + " ");
}
}
public sealed class Logger
{
//
// TODO: Add constructor logic here
public static void Write(string value)
{
StreamWriter writetext = new StreamWriter(AppDomain.CurrentDomain.BaseDirectory+"exceptionfile.txt");
writetext.WriteLine(value);
writetext.Close();
}
}
}
您的代码中有一个问题:
您需要交换这两行:
smtp.Credentials = new NetworkCredential(fromAddress, fromPassword);
smtp.UseDefaultCredentials = false;
对此:
smtp.UseDefaultCredentials = false;
smtp.Credentials = new NetworkCredential(fromAddress, fromPassword);
我已经尝试让我的应用程序发送电子邮件超过一个小时了,我已经尝试了我在网上找到的所有东西,但我仍然得到了我的问题标题中提到的例外情况。 下面是我使用的代码: 我允许在我的帐户上访问不太安全的应用程序。我也尝试过启用2FA并生成特定于应用程序的密码,但例外情况仍然存在。
在我的Gmail A/C上,我从production server运行代码后收到了以下电子邮件 嗨, 最近有人使用您的密码尝试登录您的Google帐户mymailid@gmail.com。此人正在使用电子邮件、客户端或移动设备等应用程序。 2014年1月3日星期五13:56:08点钟UTC IP地址:xxx.xx.xx.xxx(abcd.net.)地点:美国宾夕法尼亚州费城 如果您无法识别此登录尝
我想从我的应用程序发送一封电子邮件,我已经编写了以下发送邮件的代码 我正在本地主机上运行它,所以我正在做什么错误发送它。 当我发送按钮时,它会给出一个错误,比如 我应该做什么来解决这个错误并发送邮件??
嗨,我知道这个问题有点多余,但我有不同的体验,这里是我的代码发送电子邮件后,创建帐户在ASP.NET 奇怪的是,当我在本地主机上运行该网站时,gmail允许它运行,但当我在vps上运行该网站时,gmail拒绝并给出这个错误 SMTP服务器需要安全连接或客户端未通过身份验证。服务器响应为:5.5.1需要身份验证 任何帮助都会帮助tnx
这是我的密码 我该怎么办?有时起作用,有时不起作用。
我对SSIS没有太多经验。现在我正在尝试从Microsoft Exchange帐户“abc@mycompany.com”向同一个帐户“abc@mycompany.com”发送一封电子邮件。 我正在使用发送邮件任务,并且在SMTP管理连接中,我指示了smpt.office365.comsmtp服务器。 当我尝试执行流时,出现此错误:smtp 服务器需要安全连接或客户端未经过身份验证。服务器响应为:5