【问题标题】:How to send email with attachment from Azure Web Site using office365 account如何使用 office365 帐户从 Azure 网站发送带附件的电子邮件
【发布时间】:2015-05-22 03:51:06
【问题描述】:

我有 Office 365 帐户,使用它我想在部署在 Azure 网站中的 Web 应用程序中发送带有附件的电子邮件。

【问题讨论】:

    标签: c# azure office365 azure-web-app-service smtpclient


    【解决方案1】:

    这是执行此操作的函数

     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 中保留或凭据作为应用设置。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-12
      • 1970-01-01
      相关资源
      最近更新 更多