Asp.Net使用SmtpClient发送邮件(C/S框架网开源)
Asp.Net使用SmtpClient发送邮件(C/S框架网开源)
扫一扫加作者微信
SmtpClient发送邮件
using System;
using System.Collections.Generic;
using System.Text;
using System.Net.Mail;
/*
* 版权:C/S框架网 www.csframework.com
*
* 发送邮件业务逻辑
*/
namespace CSFramework.BLL
{
/// <summary>
/// 发送邮件业务逻辑
/// </summary>
public class CMail
{
/// <summary>
/// 发送邮件
/// </summary>
/// <param name="address">接收人:Eamil地址</param>
/// <param name="subject">主题</param>
/// <param name="body">邮件内容</param>
/// <param name="attachment">附件</param>
/// <param name="isBodyHtml">邮件是Html格式</param>
/// <returns></returns>
public static bool Send(string address, string subject, string body, Attachment attachment, bool isBodyHtml)
{
try
{
MailMessage mail = new MailMessage();
mail.From = new MailAddress("webadmin@csframework.com");
mail.To.Clear();
mail.To.Add(new MailAddress(address));
mail.Body = body;
mail.BodyEncoding = Encoding.UTF8;
mail.SubjectEncoding = Encoding.UTF8;
mail.Subject = subject;
mail.IsBodyHtml = isBodyHtml;
mail.Priority = System.Net.Mail.MailPriority.Normal;
if (attachment != null) mail.Attachments.Add(attachment);
SmtpClient smtp = new SmtpClient("59.36.108.188", 25);
smtp.UseDefaultCredentials = true;
smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
smtp.Credentials = new System.Net.NetworkCredential("webadmin@csframework.com", "csframework");
smtp.Send(mail);
return true;
}
catch
{
return false;
}
}
}
}
// 来源:www.CSFramework.com, C/S结构框架学习网
using System.Collections.Generic;
using System.Text;
using System.Net.Mail;
/*
* 版权:C/S框架网 www.csframework.com
*
* 发送邮件业务逻辑
*/
namespace CSFramework.BLL
{
/// <summary>
/// 发送邮件业务逻辑
/// </summary>
public class CMail
{
/// <summary>
/// 发送邮件
/// </summary>
/// <param name="address">接收人:Eamil地址</param>
/// <param name="subject">主题</param>
/// <param name="body">邮件内容</param>
/// <param name="attachment">附件</param>
/// <param name="isBodyHtml">邮件是Html格式</param>
/// <returns></returns>
public static bool Send(string address, string subject, string body, Attachment attachment, bool isBodyHtml)
{
try
{
MailMessage mail = new MailMessage();
mail.From = new MailAddress("webadmin@csframework.com");
mail.To.Clear();
mail.To.Add(new MailAddress(address));
mail.Body = body;
mail.BodyEncoding = Encoding.UTF8;
mail.SubjectEncoding = Encoding.UTF8;
mail.Subject = subject;
mail.IsBodyHtml = isBodyHtml;
mail.Priority = System.Net.Mail.MailPriority.Normal;
if (attachment != null) mail.Attachments.Add(attachment);
SmtpClient smtp = new SmtpClient("59.36.108.188", 25);
smtp.UseDefaultCredentials = true;
smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
smtp.Credentials = new System.Net.NetworkCredential("webadmin@csframework.com", "csframework");
smtp.Send(mail);
return true;
}
catch
{
return false;
}
}
}
}
// 来源:www.CSFramework.com, C/S结构框架学习网
扫一扫加作者微信
版权声明:本文为开发框架文库发布内容,转载请附上原文出处连接
NewDoc C/S框架网