从地址使用Gmail Smtp的System.Net.Mail始终是我的

时间:2012-09-23 21:51:14

标签: asp.net system.net.mail gmail-pop

我认为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);

这是收到的电子邮件:

  

来自:myacct@gmail.com   致:myacct@gmail.com   日期:太阳,2012年9月23日14:44:54 -0700(太平洋夏令时)   主题:[是]联系表格   内容类型:text / plain;字符集= US-ASCII   Content-Transfer-Encoding:quoted-printable

     

这是一个测试

我知道它可以用来工作,但现在来自我的。如果其他人都遇到这个问题,我可以得到确认吗,还是仅仅是我?

3 个答案:

答案 0 :(得分:2)

GMail(以及许多其他电子邮件提供商)不允许您更改FROM标头。这将允许电子邮件欺骗。

答案 1 :(得分:1)

要获得此结果,您必须选择godaddy等自定义电子邮件提供商或从gmail购买商业订阅。

您也可以参考 Sending Mail from Windows Azure Service, using Godaddy SMTP

答案 2 :(得分:1)

Dim attachmentFile As String = Nothing         如果FileUpload1.HasFile那么

        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