【问题标题】:Mask From Email Address smtp asp.net gmail来自电子邮件地址的掩码 smtp asp.net gmail
【发布时间】:2012-12-31 08:09:21
【问题描述】:

我正在使用 MailMessage 从 Web 应用程序发送电子邮件。我相信我有正确的代码来“屏蔽”SendEmail() 函数中的 from 名称

public static void SendEmail(string toAddress, string ccAddress, string bccAddress, string subject, string body, MemoryStream attachment, string attachmentName, bool isHtml, string fromAlias = "info@cipollainsurance.com")
    {
        using (MailMessage message = new MailMessage())
        {
            AlternateView htmlView = AlternateView.CreateAlternateViewFromString(AddHeaderAndFooter(subject, body).ToString(), new System.Net.Mime.ContentType("text/html"));

            var resources = LoadResources();

            foreach (LinkedResource resource in resources)
            {
                htmlView.LinkedResources.Add(resource);
            }

            message.AlternateViews.Add(htmlView);

            if (!string.IsNullOrEmpty(toAddress))
            {
                var addresses = toAddress.Split(',', ';');

                foreach (string address in addresses)
                {
                    message.To.Add(address);
                }
            }

            if (!string.IsNullOrEmpty(ccAddress))
            {
                var ccAddresses = ccAddress.Split(',', ';');

                foreach (string cc in ccAddresses)
                {
                    message.CC.Add(cc);
                }
            }

            if (!string.IsNullOrEmpty(bccAddress))
            {
                var bccAddresses = bccAddress.Split(',', ';');

                foreach (string bcc in bccAddresses)
                {
                    message.Bcc.Add(bcc);
                }
            }

            if (!string.IsNullOrWhiteSpace(fromAlias))
            {
                message.Sender = new MailAddress("info@cipollainsurance.com", fromAlias, System.Text.Encoding.ASCII);
            }
            message.Body = body;
            message.BodyEncoding = System.Text.Encoding.UTF8;
            message.Subject = subject;
            message.SubjectEncoding = System.Text.Encoding.UTF8;
            message.IsBodyHtml = isHtml;
            message.From = new MailAddress("info@cipollainsurance.com", "Cipolla Insurance");

            if (attachment != null)
            {
                message.Attachments.Add(new Attachment(attachment, attachmentName));
            }

            SmtpClient client = new SmtpClient();
            client.Send(message);
        }
    }

但是,发件人电子邮件地址仍然显示email 和email@webedgemedia.com,这是web.config 中指定的内容。

<smtp from="info@cipollainsurance.com" deliveryMethod="Network">
    <network host="smtp.gmail.com" enableSsl="true" port="587" password="myPassword" userName="email@webedgemedia.com" />
</smtp>

有人可以确定我缺少什么以将电子邮件发送为 info@cipollainsurance.com 吗?

【问题讨论】:

    标签: c# asp.net gmail mailmessage


    【解决方案1】:

    我不相信 GMAIL 允许您这样做 - 否则将其服务用作垃圾邮件中继非常简单。

    您最多可以设置一个不同的REPLY-TO,但您的GMAIL(帐户)电子邮件仍然是FROM。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-03-11
      • 1970-01-01
      • 1970-01-01
      • 2017-01-11
      • 2020-08-14
      • 2013-01-24
      • 2014-06-23
      • 1970-01-01
      相关资源
      最近更新 更多