我有一个在godaddy中托管的asp.net mvc网站,但是电子邮件发送无效。在服务器代码中,我写了以下
var emailmessage = new System.Web.Mail.MailMessage()
{
Subject = subject,
Body = body,
From = from,
To = to,
BodyFormat = MailFormat.Html,
Priority = MailPriority.High
};
SmtpMail.SmtpServer = "relay-hosting.secureserver.net";
SmtpMail.Send(emailmessage);
在网络配置中,我添加了代码
<system.net>
<mailSettings>
<smtp from="admin@flex.am">
<network host="relay-hosting.secureserver.net"/>
</smtp>
</mailSettings>
</system.net>
我还能做什么? 谢谢!
答案 0 :(得分:2)
以下代码段对我有用。尝试使用此代码,如果它不适合您,您是否可以记录整个异常消息。
MailMessage Msg = new MailMessage();
// Sender e-mail address.
Msg.From = new MailAddress(txtEmail.Text);
// Recipient e-mail address.
Msg.To.Add("admin@abc.com");
//Msg.Subject = txtSubject.Text;
Msg.Body ="some body message";
SmtpClient smtp = new SmtpClient();
smtp.Host = "relay-hosting.secureserver.net";
smtp.Send(Msg);