发送电子邮件问题() [英] Sending emails problem()
问题描述
我在VS2015-Asp.net上用c#准备了一个小型访谈电子邮件项目。但是同样的项目在Windows窗体中运行良好。
但是当我尝试从WebForms发送它的'给出错误,如
SMTP服务器需要安全连接或客户端没有验证。服务器响应需要5.5.1验证
我的代码: -
Hi, Iam preparing a small interview email project in VS2015-Asp.net with c#. But the same project works well in Windows Forms.
But when I try to send from WebForms its' giving error like
" The SMTP server requires a secure connection or the client has not authenticated. The server response was 5.5.1 authentication required"
My Codes :-
try
{
System.Net.Mail.MailMessage Mail = new System.Net.Mail.MailMessage();
System.Net.Mail.SmtpClient SmtpServer = new System.Net.Mail.SmtpClient("smtp.gmail.com");
Mail.From = new System.Net.Mail.MailAddress("paramu@gmail.com");
Mail.To.Add(new System.Net.Mail.MailAddress(this.DropDownList1.SelectedItem.Text));
if (TextBox1.Text.Trim().Length > 0)
{
Mail.Bcc.Add(this.TextBox1.Text);
}
if (TextBox2.Text.Trim().Length > 0)
{
Mail.CC.Add(this.TextBox2.Text);
}
Mail.Subject = this.TextBox3.Text;
if (MyInput1.PostedFile.FileName.Trim().Length>0)
{
System.Net.Mail.Attachment My_Attach = new System.Net.Mail.Attachment(MyInput1.PostedFile.FileName);
Mail.Attachments.Add(My_Attach);
}
string MyImgString64 = "/9j/4AAQSkZJRgABAQEAYABgAAD/2wBD....";
Byte[] bitmapData = Convert.FromBase64String(FixBase64ForImage(MyImgString64));
System.IO.MemoryStream streamBitmap = new System.IO.MemoryStream(bitmapData);
System.Net.Mail.LinkedResource imageToInline = new System.Net.Mail.LinkedResource(streamBitmap, System.Net.Mime.MediaTypeNames.Image.Jpeg);
imageToInline.ContentId = "MyImage";
System.Net.Mail.AlternateView av1 = System.Net.Mail.AlternateView.CreateAlternateViewFromString("<html><body><img src=cid:MyImage/><br></body></html>" + TextBox4.Text, null, System.Net.Mime.MediaTypeNames.Text.Html);
av1.LinkedResources.Add(imageToInline);
Mail.AlternateViews.Add(av1);
Mail.IsBodyHtml = true;
Mail.BodyEncoding = System.Text.Encoding.UTF8;
SmtpServer.Port = 587;
SmtpServer.Credentials = new System.Net.NetworkCredential("paramu@gmail.com", "123456");
SmtpServer.EnableSsl = true;
SmtpServer.Send(Mail);
MessageBox.Show(this, "Sending Mail Status -> Success....!!!");
}
catch (Exception ex) {
MessageBox.Show(this, ex.Message);
}
再次感谢
我尝试了什么:
从asp.net网络表单发送电子邮件
Thanks Again
What I have tried:
Sending emails from asp.net web forms
推荐答案
我正在准备一个小型的面试电子邮件项目
I am preparing a small interview email project
如果这是面试评估,那么我唯一可以给你的建议是其他人遇到了同样的问题。使用Google搜索,您可以在那里找到有用的信息。我总是从错误消息开始: SMTP服务器需要安全连接或客户端未进行身份验证 - Google搜索 [ ^ ]
这篇关于发送电子邮件问题()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!