在asp.net中发送电子邮件 [英] sending emails in asp.net
本文介绍了在asp.net中发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从我的应用程序发送邮件,地址可以是任何域,也可以是任何域.但是在我的应用程序中,我已经在web.config文件中注册了我的域名(mail.bsl.co.uk).邮件将从该域(xyz@bsl.co.uk)发送到其他域.但是我想将邮件从gmail,yahoo等发送到其他域.
I want to sent mails from my application, from address may be any domain and to address also any domain.But in my application i already registered my domain name(mail.bsl.co.uk) in web.config file.the mails are going from that domain(xyz@bsl.co.uk) to other domains.But i want to sent mails from gmail,yahoo etc to other domains.
推荐答案
您好,
检查此
Hi ,
check this
string from ="test@gmail.com"; //Replace this with your own correct Gmail Address
string to = "test1@gmail.com";//Replace this with the Email Address to whom you want to send the mail
System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
mail.To.Add(to);
mail.From = new MailAddress(from, "One Ghost", System.Text.Encoding.UTF8);
mail.Subject = "This is a test mail";
mail.SubjectEncoding = System.Text.Encoding.UTF8;
mail.Body = "This is Email Body Text";
mail.BodyEncoding = System.Text.Encoding.UTF8;
mail.IsBodyHtml = true;
mail.Priority = MailPriority.High;
SmtpClient client = new SmtpClient();
//Add the Creddentials- use your own email id and password
client.Credentials = new System.Net.NetworkCredential(from, "********");
client.Port = 587; // Gmail works on this port
client.Host = "smtp.gmail.com";
client.EnableSsl = true; //Gmail works on Server Secured Layer
try
{
client.Send(mail);
}
catch (Exception ex)
{
Exception ex2 = ex;
string errorMessage = string.Empty;
while (ex2 != null)
{
errorMessage += ex2.ToString();
ex2 = ex2.InnerException;
}
HttpContext.Current.Response.Write(errorMessage);
} // end try
最好的问候
M.Mitwalli
Best Regards
M.Mitwalli
引用它:
发送电子邮件的代码 [如何从ASP.Net应用发送电子邮件 [ ^ ]
Refer it:
code for sending email[^]
how to send an email from ASP.Net appliaction[^]
在这里查看我的答案
如何通过asp.net发送电子邮件 [ ^ ]
ASP.net的电子邮件概念 [发送电子邮件 [
see my ans here
How to send email through asp.net[^]
Email Concept of ASP.net[^]
send email[^]
这篇关于在asp.net中发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文