⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 smtputil.cs

📁 工资管理系统
💻 CS
字号:
using System;
using System.Web.Mail;
using System.Net;
using System.IO;

namespace HrSalary.util
{
	/// <summary>
	/// 发送邮件 调用System.Web.Mail.MailMessage 类
	/// </summary>
	public class SmtpUtil
	{
		private string FROM = "wxy8108123@163.com";
		private  string SMTPSERVER = "smtp.163.com";	
		private  string a_userNAME ="www"; 
		private  string PASSWORD =""; 

		public SmtpUtil(string From,string Smtpserver,string password)
		{
			this.FROM =From;   //邮件发送人
			this.SMTPSERVER=Smtpserver;//邮件服务器
			string[] array= new string[2];
			char[] ch= new char[1];
			ch[0]='@';
			array = this.FROM.Split(ch,2);
			this.a_userNAME=array[0];//从邮件地址里拆出用户名
		    this.PASSWORD=password;		
			
				//
			// TODO: 在此处添加构造函数逻辑
			//
		}
		public SmtpUtil()
		{
			//
			// TODO: 在此处添加构造函数逻辑
			//
		}
		/// <summary>
	
		/// </summary>
		/// <param name="to"></param>
		/// <param name="subject"></param>
		/// <param name="body"></param>
		public void sendHtmlMailNoHeadTail(String to,String subject,String body)
		{
			
			MailMessage mailObj = new MailMessage();
			mailObj.From = this.FROM; //谁发的
			mailObj.To = to;          //发给谁
			mailObj.Subject = subject;//邮件主题
			mailObj.Body = body;	  //邮件内容
			mailObj.BodyFormat = MailFormat.Html;//邮件形式 
			mailObj.BodyEncoding = System.Text.Encoding.GetEncoding("gb2312");//gb18030
			mailObj.Priority = MailPriority.High; 
			//以下完成验证
			mailObj.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //basic authentication
			mailObj.Fields.Add("http://schemas.microsoft.com/cdo/configuration/senda_username", this.a_userNAME); //set your a_username here
			mailObj.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", this.PASSWORD); //set your password here
			SmtpMail.SmtpServer = this.SMTPSERVER;
			SmtpMail.Send(mailObj);

		}
		
		private string ToBase64 (string str)
		{
			try
			{
				byte[] by = System.Text.Encoding.Default.GetBytes (str.ToCharArray());
				str = Convert.ToBase64String (by);
			}
			catch(Exception)
			{
			}
			return str;
		}

		private string getContext(String url)
		{
			WebClient wc = new WebClient();
			Stream stream = wc.OpenRead(url);
			StreamReader  sr = new StreamReader(stream,System.Text.Encoding.GetEncoding("gb18030"));
			string line;
			string tmp = "";
			do
			{
				line = sr.ReadLine();
				if(line!=null)
				{
					line+="\r\n";
					tmp+=line;
				}
			}while(line!=null);
			sr.Close();
			stream.Close();
			return tmp;
		}
		public string getFROM()
		{
			return  this.FROM;
		}
		public string geta_userNAME()
		{
			return  this.a_userNAME;
		}
		public string getPASSWORD()
		{
			return  this.PASSWORD;
		}
		public string getSMTPSERVER()
		{
			return  this.SMTPSERVER;
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -