无为清净楼资源网 Design By www.qnjia.com
复制代码 代码如下:
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 { }
}
}
}
}
}
标签:
.NET,发送,邮件
无为清净楼资源网 Design By www.qnjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
无为清净楼资源网 Design By www.qnjia.com
暂无评论...
RTX 5090要首发 性能要翻倍!三星展示GDDR7显存
三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。
首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。
据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。
更新日志
2024年11月16日
2024年11月16日
- 周深《反深代词》[先听版][320K/MP3][72.71MB]
- 李佳薇.2024-会发光的【黑籁音乐】【FLAC分轨】
- 后弦.2012-很有爱【天浩盛世】【WAV+CUE】
- 林俊吉.2012-将你惜命命【美华】【WAV+CUE】
- 晓雅《分享》DTS-WAV
- 黑鸭子2008-飞歌[首版][WAV+CUE]
- 黄乙玲1989-水泼落地难收回[日本天龙版][WAV+CUE]
- 周深《反深代词》[先听版][FLAC/分轨][310.97MB]
- 姜育恒1984《什么时候·串起又散落》台湾复刻版[WAV+CUE][1G]
- 那英《如今》引进版[WAV+CUE][1G]
- 蔡幸娟.1991-真的让我爱你吗【飞碟】【WAV+CUE】
- 群星.2024-好团圆电视剧原声带【TME】【FLAC分轨】
- 陈思安.1990-国语钢琴酒吧5CD【欣代唱片】【WAV+CUE】
- 莫文蔚《莫后年代20周年世纪典藏》3CD[WAV+CUE][2G]
- 张惠妹《我要快乐》华纳[WAV+CUE][1G]