这是电子邮件发送的代码,但它在try
阻止:
protected void Page_Load(object sender, EventArgs e)
{
EmailUtility email = new EmailUtility();
email.Email = new MailMessage();
string body = email.GetEmailTemplate(Server.MapPath("~/EmailTemplates"), "test.htm");
EmailMessageToken token = new EmailMessageToken();
token.TokenName = "$Name$";
token.TokenValue = "Ricky";
EmailMessageTokens tokens = new EmailMessageTokens();
tokens.Add(token);
//av.LinkedResources.Add(lr);
email.Email.Body = email.ReplaceTokens(body, tokens);
email.Email.To.Add(new MailAddress("sahil4659@gmail.com"));
email.Email.IsBodyHtml = true;
email.Email.From = new MailAddress("sahil4659@gmail.com");
email.Email.Subject = "Hello from bootcamp";
email.SMTP.Host = ConfigurationManager.AppSettings["SMTPServer"];
try
{
email.SMTP.Send(email.Email);
Response.Write("Email sent !");
}
catch (Exception ex)
{
Response.Write(ex.StackTrace);
}
}
错误是:
at System.Net.Mail.IisPickupDirectory.GetPickupDirectory()
at System.Net.Mail.SmtpClient.Send(MailMessage message)
at _Default.Page_Load(Object sender, EventArgs e) in c:\Users\Sahil\Desktop\Csharp Email Code(2)\Test website\EmailTest.aspx.cs:line 38
答案 0 :(得分:0)
我会读你的想法并假设你看到System.Net.Mail.SmtpException: Cannot get IIS pickup directory.
谷歌搜索,我看到你在网络配置中需要的SMTP配置参考。您的邮件服务器可能需要凭据,因此您可能需要以下内容:
<system.net>
<mailSettings>
<smtp from="fromaddress">
<network defaultCredentials="true"
host="smtpservername" port="smtpserverport"
userName="username" password="password" />
</smtp>
</mailSettings>
</system.net>
...在你的web.config中。实质上,配置您的Web应用程序以便能够与SMTP服务器通信。
请参阅此主题以获取更多reference和here's relevant MSDN documentation。