我收到错误消息,因为尝试发送邮件时用户代码未处理异常 [英] i got error as exception was unhandled by user code when i try to send mail

查看:98
本文介绍了我收到错误消息,因为尝试发送邮件时用户代码未处理异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好朋友,我尝试将邮件发送到某个地址,但由于用户代码未处理异常而收到错误消息

代码是

hello friends i try to send mail to an address i get an error as Exception was unhandled by user code

code is

System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
message.To.Add("jahan.vb@gmail.com");
message.Subject = "hi";
message.From = new System.Net.Mail.MailAddress("admin@contactbridge.com");
message.Body = "This is the message body";
System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("smtpout.secureserver.net");
smtp.Send(message);
Label1.Text = "message sent";

推荐答案

请参见此处:这里有发送电子邮件的完整通用方法.
使用C#发送带有或不带有附件的电子邮件: [
See here: there is a complete generic method for sending email.
Sending an Email in C# with or without attachments: generic routine.[^]


您没有提到错误".

好吧,通常来说,为了使它顺利运行,您需要查看各种设置.
喜欢:
港口开放吗?防火墙权限到位了吗?
进一步确保已在Web.Config中配置SMTP配置:
You have not mentioned about ''the error'' you got.

Well, in general for a smooth working of it you need to look at various settings.
Like:
Is the port open? Firewall permissions in place?
Further make sure you have configured SMTP configuration in Web.Config:
<system.net>
   <mailSettings>
     <smtp from="abc@somedomain.com">
       <network host="somesmtpserver" port="25" userName="name" password="pass" defaultCredentials="true" />
     </smtp>
   </mailSettings>
</system.net>


如果需要,请查看此Microsoft Video教程:
使用ASP.NET发送来自网站的电子邮件 [在ASP.NET中发送电子邮件的教程 [


If needed, have a look at this Microsoft Video tutorial:
Use ASP.NET to send Email from Website[^]
Tutorials on sending Email in ASP.NET[^]


这篇关于我收到错误消息,因为尝试发送邮件时用户代码未处理异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆