在.net.mail中使用mail.body的Html文件

时间:2011-11-29 16:57:45

标签: asp.net-mvc vb.net asp.net-mvc-3 system.net.mail

MVC3,VB.NET。我的应用程序中有一个函数,它应该使用html文件的内容作为电子邮件正文。但是到目前为止我在mail.body = file.readalltext(_body)行中失败了..任何想法?

   <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 个答案:

答案 0 :(得分:1)

mail.Body = File.ReadAllText(_body)更改为mail.Body = System.IO.File.ReadAllText(_body)

File也是Controller的成员。