在asp.net发送邮件 [英] send mail in asp .net

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

问题描述

try
       {
           string name = txt_name.Text;
           string email = txt_email.Text;
           string subject = txt_subject.Text;
           string msg = txt_area.Text;

           MailMessage m = new MailMessage();
           SmtpClient sc = new SmtpClient();
           m.From = new MailAddress("vehicletrack2013@gmail.com", "Vehicle Track");
           m.Sender = new MailAddress(email, name);
           m.To.Add(new MailAddress(destination email));
           m.To.Add(new MailAddress(destination email));

           m.Subject = subject;
           m.Body = msg;
           //similarly BCC m.Subject = "Test"; m.Body = "This is a Test Mail";
           sc.Host = "smtp.gmail.com";
           sc.Port = 587;
           sc.Credentials = new System.Net.NetworkCredential(email id from where email send, password;);

           sc.EnableSsl = true;
           sc.Send(m);
           txt_name.Text = "";
           txt_email.Text = "";
           txt_subject.Text = "";
           txt_area.Text = "";
           alert_div.Visible = true;
           alert_span.InnerHtml = "Message has been submitted";
       }
       catch (Exception ex)
       {
           alert_span.InnerHtml = "Could not send the e-mail";
       }







当我在.net中使用它而不是它正常工作但是当我上传我的网站比它不能工作

请帮助我




when i use this in .net than it work properly but when i upload my site than it cant work
please help me

推荐答案

当你上传这个项目时,你不能将gmail帐户设置为源地址bcoz服务器gmail服务器阻止你发送邮件。



所以不要使用gmail地址只需在你的服务器上创建一个电子邮件ID然后试试。

希望它能够工作
you cant set gmail account as source address bcoz when you upload this project onto server gmail server prevent you to send mail.

so instead of using gmail address just create one email id on your server then try.
hope it will work


请检查机器上是否有部署代码的服务。

可能是没有访问太SMTP服务器



或者看起来SMTP有些问题。所以首先检查gmail smtp。如果它有效,那么稍后用你的替换gmail smtp。



SmtpClient tSmtpClient = new SmtpClient(smtp.gmail.com,587);



-SG
Please check the machine for services on which you deployed your code.
may be that dont have access too SMTP server

Or It seems some problem with SMTP . So firstly check for gmail smtp. if it works then later replace gmail smtp by yours.

SmtpClient tSmtpClient = new SmtpClient("smtp.gmail.com",587);

-SG


请看一下文章。它完美无缺。
please have a look in this article. it works perfectly.


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

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