如何通过我的网站发送电子邮件 [英] how can send emails through my website
本文介绍了如何通过我的网站发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的代码是这样的:
MailMessage邮件= 新 MailMessage();
mail.To.Add(Txt_Email.Text);
mail.From = 新 MailAddress(" span>);
mail.Subject = " ;
mail.Body = " ;
SmtpClient smtp = 新 SmtpClient(" );
// 待办事项:添加SMTP身份验证
// smtp.Credentials = new NetworkCredentials("user","password");
smtp.Send(mail);
但我提出了一个错误.请解决我的问题
解决方案
尝试此方法
公共 静态 布尔值 SendingMail(字符串发件人,字符串收件人,字符串主题,字符串正文) { 尝试 { MailMessage m = 新 MailMessage(" ,收件人); m.Subject =主题; m.Body =身体; m.IsBodyHtml = true ; m.From = 新 MailAddress(From); m.To.Add(新 MailAddress(To)); SmtpClient smtp = 新 SmtpClient(); smtp.Host = " ; NetworkCredential authinfo = 新 NetworkCredential(" , pass @ 1234"); smtp.UseDefaultCredentials = false ; smtp.Credentials = authinfo; smtp.Send(m); 返回 真; } 捕获(例外) { 返回 假; } }
希望这能给您一些想法
您必须在webconfig文件或同一页面中提供urs和密码的邮递区号.
使用 System.Net.Mail; 添加 此 smtp.Credentials = 新 System.Net.NetworkCredential (" ," YourGmailPassword"); smtp.EnableSsl = true ; smtp.Send(邮件); 如果问题仍然存在 添加 smpt.port = 587 ;
在此处查看我的信息
如何通过asp.net发送电子邮件 [ ^ ]
hai everybody. i am new for creating mailserver. so i need a help from you. i create one form. after filling all the detaills, i nedd to send mail to the customer.
my code is like this:
MailMessage mail = new MailMessage();
mail.To.Add(Txt_Email.Text);
mail.From = new MailAddress("myemailid");
mail.Subject = "Sending an email";
mail.Body = "Date ";
SmtpClient smtp = new SmtpClient("mail.gmail.com");
//TODO: Add SMTP Authentication
//smtp.Credentials = new NetworkCredentials("user", "password");
smtp.Send(mail);
but i raise an error. plz any solve my problem
解决方案
try this method
public static Boolean SendingMail(string From, string To, string Subject, string Body) { try { MailMessage m = new MailMessage("<id@gmail.com>", To); m.Subject = Subject; m.Body = Body; m.IsBodyHtml = true; m.From = new MailAddress(From); m.To.Add(new MailAddress(To)); SmtpClient smtp = new SmtpClient(); smtp.Host = "mail.google.com"; NetworkCredential authinfo = new NetworkCredential("id@gmail.com", "pass@1234"); smtp.UseDefaultCredentials = false; smtp.Credentials = authinfo; smtp.Send(m); return true; } catch (Exception ex) { return false; } }
hope this ll give some idea
u ve to give the mailid of urs and password either in webconfig file or in the same page.
using System.Net.Mail; add this smtp.Credentials = new System.Net.NetworkCredential ("YourUserName@gmail.com","YourGmailPassword"); smtp.EnableSsl = true; smtp.Send(mail); if problem still persist add smpt.port=587;
See my post here
How to send email through asp.net[^]
这篇关于如何通过我的网站发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文