用asp.net发送邮件 [英] send mail with asp.net

查看:109
本文介绍了用asp.net发送邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用asp.net发送邮件的代码
我使用以下鳕鱼,但有错误.

i need code for send mail with asp.net
i use following cod but it has error.

protected void btnSubmit_Click(object sender, EventArgs e)
    {
        try
            {
             MailMessage message = new MailMessage(txtFrom.Text, txtTo.Text, txtSubject.Text, txtBody.Text);

            SmtpClient emailClient=new SmtpClient(txtSMTPServer.Text);
            emailClient.Send (message);
            litStatus.Text="Message Sent";
            }
        catch (Exception ex) 
        {
            litStatus.Text=ex.ToString();
       }

}

推荐答案

您遇到什么异常? xtSMTPServer.Text的值是多少?大多数SMTP服务器都需要凭据才能发送邮件,并且您没有设置我可以看到的任何内容.
What exception are you getting? What''s the value of xtSMTPServer.Text? Most SMTP servers require credentials in order to send mail, and you''re not setting any that I can see.


尝试一下,
Try this,
MailMessage msgMail = new MailMessage();
SmtpClient smtp = new SmtpClient("servername", "portno");
msgMail.From = new MailAddress("fromaddress", "from name");
msgMail.To.Add(new MailAddress("toaddress"));

msgMail.Subject = "Subject";
msgMail.Body = "Body";
smtp.Send(msgMail);


可能是由于各种原因.您需要一一看待它们.
港口开放吗?防火墙权限到位了吗?
进一步确保已在Web.Config中配置SMTP配置:
It can be because of various reasons. You need to look at them one by one.
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发送来自网站的电子邮件 [


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


这篇关于用asp.net发送邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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