无法在asp.net Web应用程序中发送电子邮件 [英] Unable to send email in asp.net web application

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

问题描述

谁能告诉我我要去哪里错了.多谢.

我确信所有细节都是正确的.我仍然感到异常,不知道罪魁祸首是谁.

非常感谢.

Can anyone please advise where I am going wrong. Thanks a ton.

I am sure all the details were correct. Still i am getting exception and I have no clue who is the culprit.

Thanks a lot.

protected void ButtonSubmit_Click(object sender, EventArgs e)
    {
        MailMessage mail = new MailMessage();
        

            mail.From = new MailAddress(TextBoxEmail.Text, TextBoxCompanyName.Text);
            mail.To.Add(new MailAddress("indra.rikkala@achirconsultancy.com"));
           
            mail.Subject = TextBoxSubject.Text;
            mail.Body = TextBoxMessage.Text;

        SmtpClient client
            = new SmtpClient("smtp.achirconsultancy.com");
        client.Credentials = new System.Net.NetworkCredential("indra.rikkala@achirconsultancy.com", "zzzzzzzz");
        try
        {
           
            client.Port = 25;
            client.Send(mail);
        }
        catch (Exception ex) 
        {
            Labeltext.Text = " Error occured. Sorry for the inconvinence";
            return;
            /*Response.Write(" Unhandled expection occured please check the Email ID that you have entered");*/

        }

        Labeltext.Text = "Your message has been successfully sent. Thank you";
               
    }

推荐答案

您遇到什么异常?
港口开放吗?防火墙权限到位了吗?
进一步确保已在Web.Config中配置SMTP配置:
What exception you are getting?
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[^]

If needed, there are lots of article on this very site on how to send emails


是否必须在web.config中包含SMTP配置详细信息.
我很确定即使没有那也能实现.例外是连接失败.

那是不是在凭据部分中我提供了错误的详细信息?
Is it mandatory to include SMTP configuration details in web.config.
I am pretty sure I have achieved it even without that.exception was connect failure.

Is that mean the in credential section I am giving wrong details?


我在您设置客户端对象的Host属性的代码中看不到任何地方.这是必需的,以及您设置的Port属性.在此处检查. microsoft.com/en-us/library/system.net.mail.smtpclient.aspx"target =" _ blank"title =" New>
I don''t see anyplace in your code where you set the Host property of the client object. That''s required, along with the Port property that you have set. Check here[


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

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