Using a Html file for mail.body in .net.mail

廉价感情. 提交于 2019-12-25 02:07:38

问题


MVC3, VB.NET. I have a function in my app that is supposed to use a html file's contents for the email body. However what I have so far is failing at the mail.body = file.readalltext(_body) line.. Any ideas??

   <Authorize(Roles:="Admin")>
    Function Notification(ByVal _email As String) As ActionResult


        Dim _body = Path.Combine((AppDomain.CurrentDomain.BaseDirectory) + "HtmlEmails\") + "HolidayEmail.htm"

        Dim SmtpServer As New SmtpClient()
        Dim mail As New MailMessage()
        mail.To.Add(_email)
        mail.From = New MailAddress("xxxxxx.Automated@xxxxxxxxx.com")

        mail.Subject = "Happy Holidays From xxxxx"
        mail.Body = File.ReadAllText(_body)
        mail.IsBodyHtml = True
        Dim smtp As New SmtpClient("mail.xxxxxxxxx.com")
        smtp.Credentials = New System.Net.NetworkCredential("xxxxxx.Automated@xxxxxxxxxxxxxxx.com", "xxxxxxxxxx")
        smtp.Port = "587"
        smtp.Send(mail)

        Return RedirectToAction("LogOn", "Account")
    End Function

回答1:


Change mail.Body = File.ReadAllText(_body) to mail.Body = System.IO.File.ReadAllText(_body).

File is also a member of Controller.



来源:https://stackoverflow.com/questions/8314628/using-a-html-file-for-mail-body-in-net-mail

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!