[英]System.Net.Mail using Gmail Smtp from address is always mine
I think that Gmail is rewriting the from address and using the account that is provided in the network credentials for the from. 我认为Gmail正在重写发件人地址并使用网络凭据中提供的帐户。
MailMessage message = new MailMessage();
message.From = new MailAddress("jimmy@gmail.com");
message.To.Add(new MailAddress("myacct@gmail.com"));
message.Subject = "[Yep] Contact Form";
message.Body = msg;
message.IsBodyHtml = false;
SmtpClient client = new SmtpClient();
client.UseDefaultCredentials = false;
NetworkCredential networkCredentials = new NetworkCredential("myacct@gmail.com", "pass");
client.Credentials = networkCredentials;
client.EnableSsl = true;
client.Host = "smtp.gmail.com";
client.Port = 587;
try
{
client.Send(message);
This is the received email: 这是收到的电子邮件:
From: myacct@gmail.com To: myacct@gmail.com Date: Sun, 23 Sep 2012 14:44:54 -0700 (PDT) Subject: [Yep] Contact Form Content-Type: text/plain; 来自:myacct@gmail.com致:myacct@gmail.com日期:星期日,2012年9月23日14:44:54 -0700(PDT)主题:[是]联系表格内容类型:text / plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable charset = us-ascii Content-Transfer-Encoding:quoted-printable
This is a test 这是一个测验
I know it use to work but now the from is always mine. 我知道它可以用来工作,但现在来自总是我的。 Can I get a confirmation if everyone else is having this issue or is it just me? 如果其他人都有这个问题,我可以得到确认吗,还是仅仅是我?
GMail (and many other email providers) will not allow you to alter the FROM header. GMail(以及许多其他电子邮件提供商)不允许您更改FROM标头。 That would allow email spoofing. 这将允许电子邮件欺骗。
To achieve this result you will have to go for custom email provider like godaddy or buy business subscription from gmail. 要实现此结果,您必须选择godaddy等自定义电子邮件提供商或从gmail购买商业订阅。
You can also refer Sending Mail from Windows Azure Service, using Godaddy SMTP 您还可以使用Godaddy SMTP引用从Windows Azure服务发送邮件
Dim attachmentFile As String = Nothing If FileUpload1.HasFile Then Dim attachmentFile As String = Nothing If FileUpload1.HasFile Then
Try
FileUpload1.SaveAs("C:\files\" + FileUpload1.FileName)
attachmentFile = FileUpload1.PostedFile.FileName
Catch ex As Exception
litStatus.Text = "File Upload Failed !! " + ex.Message.ToString()
End Try
Try
Dim mail As New MailMessage()
Dim SmtpServer As New SmtpClient("smtp.gmail.com")
mail.From = New MailAddress("your-gamila-ddress@gmail.com")
'you have to provide your gmail address as from address'
mail.[To].Add(txtTo.Text)
mail.Subject = txtSubject.Text
mail.Body = txtBody.Text
Dim attachment As System.Net.Mail.Attachment
attachment = New System.Net.Mail.Attachment(attachmentFile)
mail.Attachments.Add(attachment)
SmtpServer.Port = 587
SmtpServer.Credentials = New System.Net.NetworkCredential("gamil-username", "gmail-passowrd")
'you have to provide you gamil username and password'
SmtpServer.EnableSsl = True
SmtpServer.Send(mail)
litStatus.Text = "Email successfully sent."
Catch ex As Exception
litStatus.Text = "Mail Send Failed ! " + ex.Message.ToString()
End Try
Else
litStatus.Text = "Please select a file for uploading"
End If
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.