请问有没有asp.net c# email发送的类的源码?
发布网友
发布时间:2022-04-21 15:35
我来回答
共3个回答
热心网友
时间:2024-01-05 13:46
using System.Collections.Generic;
using System.Text;
using System.Net.Mail;
using System.Net;namespace cn.SwordYang
...{
public class MailSender
...{
protected int emailPriority=1; //邮件紧急程度
protected string mailFormat="text"; //邮件类型
protected string fromMail; //发件人邮箱地址
protected string toMail; //收件人地址
protected string subject; //邮件主题
protected string body; //邮件内容
protected Encoding mailEncoding=Encoding.GetEncoding(936); //邮件编码
//protected int isLocalSmtp=2; //是否启用本地smtp服务器
protected string smtpServer;
protected int smtpPort=25;
//protected int isSmtpAuthenticate=1; //是否需要验证
protected bool isSSL=true; //是否需要SSL认证
protected string mailUserName; //用户名
protected string mailPassWord; //密码
属性#region 属性
/**//// <summary>
/// 邮件紧急程度,0为低,1为普通,2为高
/// </summary>
public int EmailPriority
...{
get...{return emailPriority;}
set...{emailPriority=value;}} /**//// <summary>
/// 邮件类型 text为纯文本型,html为Html编码型
/// </summary>
public string MailFormat
...{
get...{return mailFormat;}
set...{mailFormat=value;}}
/**//// <summary>
/// 发件人邮箱地址
/// </summary>
public string FromMail
...{
get ...{ return fromMail; }
set ...{ fromMail = value; }}
/**//// <summary>
/// 收件人地址
/// </summary>
public string ToMail
...{
get ...{ return toMail; }
set ...{ toMail = value; }}
/**//// <summary>
/// 邮件主题
/// </summary>
public string Subject
...{
get ...{ return subject; }
set ...{ subject = value; }}/**//// <summary>
/// 邮件内容
/// </summary>
public string Body
...{
get ...{ return body; }
set ...{ body = value; }}
/**//// <summary>
/// 邮件编码格式
/// </summary>
public Encoding MailEncoding
...{
get...{return mailEncoding;}
set...{mailEncoding=value;}
}
/**//// <summary>
/// 是否启用本地smtp服务器,1为启用本地,2为启用远程smtp,默认为2
/// </summary>
/**//*
public int IsLocalSmtp
{
get{return isLocalSmtp;}
set{isLocalSmtp=value;}
}
*//**//// <summary>
/// 远程stmp服务器名称
/// </summary>
public string SmtpServer
...{
get ...{ return smtpServer; }
set ...{ smtpServer = value; }
}/**//// <summary>
/// 远程stmp服务器端口号
/// </summary>
public int SmtpPort
...{
get ...{ return smtpPort; }
set ...{ smtpPort = value; }
}/**//*
* /// <summary>
/// 是否需要验证 0为不验证,1为BASIC验证,2为NTLM验证方式
/// </summary>
public int IsSmtpAuthenticate
{
get { return isSmtpAuthenticate; }
set { isSmtpAuthenticate = value; }
}*/
/**//// <summary>
/// 是否需要SSL认证
/// </summary>
public bool IsSSL
...{
get ...{ return isSSL; }
set ...{ isSSL = value; }
}/**//// <summary>
/// 邮箱用户名
/// </summary>
public string MailUserName
...{
get ...{ return mailUserName; }
set ...{ mailUserName = value; }}/**//// <summary>
/// 邮箱密码
/// </summary>public string MailPassWord
...{
get ...{ return mailPassWord; }
set ...{ mailPassWord = value; }
} #endregion
public string SendEmail()
...{ try
...{
MailMessage msg = new MailMessage(fromMail,toMail); msg.Subject = subject;
msg.Body = body;
msg.BodyEncoding =mailEncoding;
//是否启用html
switch (mailFormat)
...{
case "html":
msg.IsBodyHtml=true;
break;
case "text":
msg.IsBodyHtml=false;
break;
} switch (emailPriority)
...{
case 2:
msg.Priority = MailPriority.High;
break;
case 1:
msg.Priority = MailPriority.Normal;
break;
case 0:
msg.Priority = MailPriority.Low;
break;
} SmtpClient SC=new SmtpClient(smtpServer,smtpPort);
if (!String.IsNullOrEmpty(mailUserName) && !String.IsNullOrEmpty(mailPassWord))
...{
SC.Credentials = new NetworkCredential(mailUserName, mailPassWord);
} SC.EnableSsl=isSSL;
SC.Send(msg);
return "Send Mail OK";}
catch (Exception ex)
...{
return ex.Message;
}
}
}
}
热心网友
时间:2024-01-05 13:47
//发送Internet邮件
try
{
SmtpClient client = new SmtpClient("smtp.sina.com【邮件服务器,比如这个就是新浪邮箱的发件服务器】");
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential("发送邮箱的用户名", "发送邮箱的密码");
client.DeliveryMethod = SmtpDeliveryMethod.Network;
MailMessage mail = new MailMessage();
mail.From = new MailAddress("接收邮件的邮箱,就是你要发给谁");
mail.To.Add("抄送给谁,可以不填");
mail.Subject = "邮件标题";
mail.BodyEncoding = System.Text.Encoding.Default;
mail.Body = "邮件内容";
if (list != null)
{
foreach (Attachment item in list)
{
mail.Attachments.Add(item);
}
}
mail.IsBodyHtml = true;
client.Send(mail);
Response.Write("<script>alert('发送成功');</script>");
}
catch (Exception ex)
{
Response.Write("<script>alert('" + ex.Message + "');</script>");
}
热心网友
时间:2024-01-05 13:47
有个用来处理email邮件的控件Spire.Email,还不错,你可以试一下,这里的代码教程,你参考看看