使用HTML文件中.net.mail mail.body [英] Using a Html file for mail.body in .net.mail
本文介绍了使用HTML文件中.net.mail mail.body的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
MVC3,VB.NET。我在我的应用程序的函数应该使用一个HTML文件的内容的电子邮件正文。不过我至今是在mail.body = file.readalltext(_body)线失败。任何想法?
<授权(角色:=管理员)>
功能通知(BYVAL _EMAIL作为字符串)作为的ActionResult
暗淡_body = Path.Combine((AppDomain.CurrentDomain.BaseDirectory)+HtmlEmails \\)+HolidayEmail.htm 昏暗SMTPSERVER作为新SmtpClient()
昏暗的邮件作为MAILMESSAGE新()
mail.To.Add(_EMAIL)
mail.From =新MailAddress(xxxxxx.Automated@xxxxxxxxx.com) mail.Subject =节日快乐从XXXXX
mail.Body = File.ReadAllText(_body)
mail.IsBodyHtml = TRUE
昏暗的SMTP作为新SmtpClient(mail.xxxxxxxxx.com)
smtp.Credentials =新System.Net.NetworkCredential(xxxxxx.Automated@xxxxxxxxxxxxxxx.com,XXXXXXXXXX)
smtp.Port =587
smtp.Send(邮件) 返回RedirectToAction(登录,帐户)
结束功能
解决方案
修改 mail.Body = File.ReadAllText(_body)
到邮件。车身= System.IO.File.ReadAllText(_body)
。
文件
也控制器
。
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
解决方案
Change mail.Body = File.ReadAllText(_body)
to mail.Body = System.IO.File.ReadAllText(_body)
.
File
is also a member of Controller
.
这篇关于使用HTML文件中.net.mail mail.body的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文