在C#ASP.NET查询SMTP PORT中发送电子邮件 [英] Email sending in C# ASP.NET query SMTP PORT
本文介绍了在C#ASP.NET查询SMTP PORT中发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我们使用SMTP端口587通过C#ASP.NET中的gmail关联帐户发送电子邮件。那么我们如何应用端口/主机从yahoo,outlook等任何帐户发送电子邮件?
we use the SMTP ports 587 for sending emails through gmail associated account in C# ASP.NET. So how can we apply a port/host to send emails from any account like yahoo,outlook etc?
推荐答案
这是SMTP电子邮件发件人的工作代码
public static bool SendEmail(string attachment)
{
try
{
string smtp = "smtp.gmail.com";
int port = 587;
string from = "Gmail Account";
string password = "Account Password";
string DisplayName = "Email Subject";
bool IsHTML = false;
bool IsSSLEnable = true;
MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient(smtp);
mail.From = new MailAddress(from, DisplayName);
mail.To.Add("Reciever Email");
mail.Subject = DisplayName ;
mail.IsBodyHtml = IsHTML;
mail.Attachments.Add(new Attachment(attachment));
mail.Body = "This is auto Generated Report";
SmtpServer.UseDefaultCredentials = false;
SmtpServer.Credentials = new System.Net.NetworkCredential(from, password);
SmtpServer.EnableSsl = IsSSLEnable;
SmtpServer.Send(mail);
return true;
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
return false;
}
}
这篇关于在C#ASP.NET查询SMTP PORT中发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文