createmailmessage不发送邮件

时间:2012-08-07 13:06:17

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

我正在尝试将一些填写在contactform中的信息发送到邮件,并将html文件作为正文文件。 我一直收到nullvalue的错误:

Dim mailMes As System.Net.Mail.MailMessage = _
    mailDef.CreateMailMessage(toAdres, replacements, New System.Web.UI.Control())

当我在createmessage中插入html文件的字符串时,它似乎发送了一封邮件而不是html文件。我只看到字符串而不是替换内容。

我做错了什么?功能在模块(mvc应用程序)

这是我的代码:

Imports System.Net.Mail
' ...

Dim mailDef As MailDefinition = New MailDefinition()
mailDef.BodyFileName = "~/Templates/ContactForm-EmailTemplate.htm"
mailDef.IsBodyHtml = True
mailDef.From = fromAdres
mailDef.Subject = subject

Dim mailMes As MailMessage = _
    mailDef.CreateMailMessage(toAdres, replacements, New System.Web.UI.Control())
mailMes.Sender = New MailAddress(fromAdres, displayName)

Dim smtpClient As SmtpClient = New SmtpClient()
smtpClient.Send(mailMes)

0 个答案:

没有答案