使用C#在ASP.Net中发送电子邮件

问题描述:

//mail sending
            MailMessage mail = new MailMessage();
            mail.From = new MailAddress("abc@gmail.com");
            mail.To.Add("abc@gmail.com");

            //to send mail on textbox value use this code.
            mail.To.Add("abc@gmail.com");
            mail.IsBodyHtml = true;

            mail.Subject = "ABC";

            mail.Body = "this is mail body";
            SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);

            smtp.Credentials = new System.Net.NetworkCredential("abc@gmail.com", "9876543210");
            smtp.EnableSsl = true;
            smtp.Send(mail);

            TxtFullName.Text = "";
            TxtEmailID.Text = "";
            TxtContactNo.Text = "";
            TxtFeedback.Text = "";

            LblMsg.Text = "Your Mail is Submited...";







i am used above code for Email sending, it is work well project are run as Local host....
but when project are run on Server, then mail are not send... it is display the error...

Error Is :-

Details: To enable the details of this specific error message to be viewable on remote machines, please create a <customErrors> tag within a "web.config" configuration file located in the root directory of the current web application. This <customErrors> tag should then have its "mode" attribute set to "Off".







<configuration>
    <system.web>
        <customErrors mode="Off"/>
    </system.web>
</configuration>





Thanx提前。



Thanx in advance.

您好,您必须在smpt.send之前添加smtp主机名或smpt servername(邮件)



请参阅以下链接:

使用ASP.NET和C#发送邮件/联系表单 [ ^ ]
Hi, you have to add smtp hostname or smpt servername before smpt.send(mail)

see the link below:
Send Mail / Contact Form using ASP.NET and C#[^]