复制代码 代码如下:
using System;
using System.Collections.Generic;
using System.Text;
using System.Net.Mail;
using System.Net;
namespace MyQuery.Utils
{
/// <summary>
/// 封装邮件处理
/// by 贾世义 2011-6-3
/// </summary>
public static class MailHelper
{
private static string smtpHost = null;
private static int smptPort = 25;
private static bool smtpIsUserCredentials = false;
private static string smtpCredentialAccount = null;
private static string smtpCredentialPassword = null;
/// <summary>
/// 设置发送邮件参数
/// </summary>
/// <param name="host">smtp服务器地址或名称</param>
/// <param name="port">smtp服务端口 一般为25</param>
/// <param name="isUserCredentials">是否需要认证</param>
/// <param name="account">需要认证时的用户</param>
/// <param name="password">需要认证时的用户的密码</param>
public static void SetParameters(string host, int port, bool isUserCredentials, string account, string password)
{
smtpHost = host;
smptPort = port;
smtpIsUserCredentials = isUserCredentials;
smtpCredentialAccount = account;
smtpCredentialPassword = password;
}
/// <summary>
/// 设置发送邮件参数 取配置
/// </summary>
private static void setParameters()
{
if (String.IsNullOrEmpty(smtpHost))
{
smtpHost = WebHelper.GetAppConfig("SmtpHost");
smptPort = DataHelper.GetIntValue(WebHelper.GetAppConfig("SmptPort"), 25);
smtpIsUserCredentials = Constants.TRUE_ID.Equals(WebHelper.GetAppConfig("SmtpIsUserCredentials"));
smtpCredentialAccount = WebHelper.GetAppConfig("SmtpCredentialAccount");
smtpCredentialPassword = WebHelper.GetAppConfig("SmtpCredentialPassword");
}
}
/// <summary>
/// 发送邮件 发送邮件错误不会抛出异常
/// </summary>
/// <param name="receivers">收件人</param>
/// <param name="title">标题/主题</param>
/// <param name="content">信件内容</param>
/// <param name="sender">发件人 空则取系统配置</param>
public static void SendMail(string receivers, string title, string content, string sender)
{
if (!String.IsNullOrEmpty(receivers))
{
//初始化参数
setParameters();
if (!String.IsNullOrEmpty(smtpHost))
{
try
{
SmtpClient smtp = new SmtpClient(smtpHost, smptPort);
if (smtpIsUserCredentials)
{
smtp.UseDefaultCredentials = true;
smtp.Credentials = new NetworkCredential(smtpCredentialAccount, smtpCredentialPassword); ;
}
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
if (String.IsNullOrEmpty(sender))
{
sender = smtpCredentialAccount;
}
foreach (string receiver in DataHelper.GetStrings(receivers))
{
MailMessage msg = new MailMessage(sender, receiver, title, content);
msg.BodyEncoding = Encoding.UTF8;
msg.SubjectEncoding = Encoding.UTF8;
msg.IsBodyHtml = true;
smtp.Send(msg);
msg.Dispose();
}
}
catch { }
}
}
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
using System.Net.Mail;
using System.Net;
namespace MyQuery.Utils
{
/// <summary>
/// 封装邮件处理
/// by 贾世义 2011-6-3
/// </summary>
public static class MailHelper
{
private static string smtpHost = null;
private static int smptPort = 25;
private static bool smtpIsUserCredentials = false;
private static string smtpCredentialAccount = null;
private static string smtpCredentialPassword = null;
/// <summary>
/// 设置发送邮件参数
/// </summary>
/// <param name="host">smtp服务器地址或名称</param>
/// <param name="port">smtp服务端口 一般为25</param>
/// <param name="isUserCredentials">是否需要认证</param>
/// <param name="account">需要认证时的用户</param>
/// <param name="password">需要认证时的用户的密码</param>
public static void SetParameters(string host, int port, bool isUserCredentials, string account, string password)
{
smtpHost = host;
smptPort = port;
smtpIsUserCredentials = isUserCredentials;
smtpCredentialAccount = account;
smtpCredentialPassword = password;
}
/// <summary>
/// 设置发送邮件参数 取配置
/// </summary>
private static void setParameters()
{
if (String.IsNullOrEmpty(smtpHost))
{
smtpHost = WebHelper.GetAppConfig("SmtpHost");
smptPort = DataHelper.GetIntValue(WebHelper.GetAppConfig("SmptPort"), 25);
smtpIsUserCredentials = Constants.TRUE_ID.Equals(WebHelper.GetAppConfig("SmtpIsUserCredentials"));
smtpCredentialAccount = WebHelper.GetAppConfig("SmtpCredentialAccount");
smtpCredentialPassword = WebHelper.GetAppConfig("SmtpCredentialPassword");
}
}
/// <summary>
/// 发送邮件 发送邮件错误不会抛出异常
/// </summary>
/// <param name="receivers">收件人</param>
/// <param name="title">标题/主题</param>
/// <param name="content">信件内容</param>
/// <param name="sender">发件人 空则取系统配置</param>
public static void SendMail(string receivers, string title, string content, string sender)
{
if (!String.IsNullOrEmpty(receivers))
{
//初始化参数
setParameters();
if (!String.IsNullOrEmpty(smtpHost))
{
try
{
SmtpClient smtp = new SmtpClient(smtpHost, smptPort);
if (smtpIsUserCredentials)
{
smtp.UseDefaultCredentials = true;
smtp.Credentials = new NetworkCredential(smtpCredentialAccount, smtpCredentialPassword); ;
}
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
if (String.IsNullOrEmpty(sender))
{
sender = smtpCredentialAccount;
}
foreach (string receiver in DataHelper.GetStrings(receivers))
{
MailMessage msg = new MailMessage(sender, receiver, title, content);
msg.BodyEncoding = Encoding.UTF8;
msg.SubjectEncoding = Encoding.UTF8;
msg.IsBodyHtml = true;
smtp.Send(msg);
msg.Dispose();
}
}
catch { }
}
}
}
}
}
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
暂无评论...
更新日志
2024年11月27日
2024年11月27日
- 凤飞飞《我们的主题曲》飞跃制作[正版原抓WAV+CUE]
- 刘嘉亮《亮情歌2》[WAV+CUE][1G]
- 红馆40·谭咏麟《歌者恋歌浓情30年演唱会》3CD[低速原抓WAV+CUE][1.8G]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[320K/MP3][193.25MB]
- 【轻音乐】曼托凡尼乐团《精选辑》2CD.1998[FLAC+CUE整轨]
- 邝美云《心中有爱》1989年香港DMIJP版1MTO东芝首版[WAV+CUE]
- 群星《情叹-发烧女声DSD》天籁女声发烧碟[WAV+CUE]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[FLAC/分轨][748.03MB]
- 理想混蛋《Origin Sessions》[320K/MP3][37.47MB]
- 公馆青少年《我其实一点都不酷》[320K/MP3][78.78MB]
- 群星《情叹-发烧男声DSD》最值得珍藏的完美男声[WAV+CUE]
- 群星《国韵飘香·贵妃醉酒HQCD黑胶王》2CD[WAV]
- 卫兰《DAUGHTER》【低速原抓WAV+CUE】
- 公馆青少年《我其实一点都不酷》[FLAC/分轨][398.22MB]
- ZWEI《迟暮的花 (Explicit)》[320K/MP3][57.16MB]