System.Net.Mail使用Gmail Smtp从地址永远是我的



我认为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 (PDT) 主题:[是的]联系表格 内容类型:文本/纯文本;字符集=US-ASCII 内容传输编码:带引号可打印

这是个测试

我知道它曾经有效,但现在从总是我的。如果其他人都遇到此问题,或者只有我一个人,我可以得到确认吗?

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

要实现此结果,您必须选择自定义电子邮件提供商,例如 godaddy 或从 Gmail 购买业务订阅。

您也可以参考使用 Godaddy 发送邮件 Windows Azure 服务<</p>

div class="one_answers">

将附件文件调暗为字符串 = 无 如果文件上传1.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

最新更新