我有Office 365帐户,使用它我想在我的Web应用程序中发送带有附件的电子邮件,该应用程序部署在Azure网站中。
答案 0 :(得分:0)
这是执行此功能的功能
public void SendEmailWithAttachment()
{
var objMailMessage = new MailMessage("EnterFromEmailAddress", "ReceiverEmailAddress")
{
Subject = "EnterEmailSubject",
IsBodyHtml = true,
Body = "EnterEmailBody"
};
//You can add more attachments
objMailMessage.Attachments.Add(new Attachment("EnterAttachmentLocationPath"));
var smtp = new SmtpClient("smtp.office365.com");
var login = new NetworkCredential("SenderEmail","SenderEmailPAssword");
smtp.Credentials = login;
smtp.Port = 587;
smtp.EnableSsl = true;
smtp.Send(objMailMessage);
}
最好将web.config中的凭据或凭据保留为应用程序设置。