0
我正在使用MailMessage從Web應用程序發送電子郵件。我相信我有在SendEmail()
功能從電子郵件地址掩碼smtp asp.net gmail
public static void SendEmail(string toAddress, string ccAddress, string bccAddress, string subject, string body, MemoryStream attachment, string attachmentName, bool isHtml, string fromAlias = "[email protected]")
{
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("[email protected]", 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("[email protected]", "Cipolla Insurance");
if (attachment != null)
{
message.Attachments.Add(new Attachment(attachment, attachmentName));
}
SmtpClient client = new SmtpClient();
client.Send(message);
}
}
然而,從電子郵件地址仍然說email
和[email protected]
這是什麼在web.config
規定在正確的代碼到來自名爲「面具」。
<smtp from="[email protected]" deliveryMethod="Network">
<network host="smtp.gmail.com" enableSsl="true" port="587" password="myPassword" userName="[email protected]" />
</smtp>
有人能確定我錯過了什麼發送電子郵件作爲[email protected]?