sendMail.cs
资源名称:Email.rar [点击查看]
上传用户:hncsjykj
上传日期:2022-08-09
资源大小:461k
文件大小:3k
源码类别:
Email客户端
开发平台:
C#
- using System;
- using System.Data;
- using System.Configuration;
- using System.Net.Mail;
- namespace LYBemail
- {
- /// <summary>
- ///GMail 的摘要说明
- /// </summary>
- public class sendMail
- {
- public sendMail()
- {
- //
- //TODO: 在此处添加构造函数逻辑
- //
- }
- private string smtp;
- public string _smtp
- {
- get { return smtp; }
- set { smtp = value; }
- }
- private string port;
- public string _port
- {
- get { return port; }
- set { port = value; }
- }
- private string userName;
- public string _userName
- {
- get{return userName;}
- set {userName=value;}
- }
- private string pwd;
- public string _pwd
- {
- get{return pwd;}
- set{pwd=value;}
- }
- private string fromName;
- public string _fromName
- {
- get { return fromName; }
- set { fromName = value; }
- }
- private string toName;
- public string _toName
- {
- get { return toName; }
- set { toName = value; }
- }
- private string subject;
- public string _subject
- {
- get { return subject; }
- set { subject = value; }
- }
- private string content;
- public string _content
- {
- get { return content; }
- set { content = value; }
- }
- private bool isHtml;
- public bool _isHtml
- {
- get { return isHtml; }
- set { isHtml = value; }
- }
- public bool send()
- {
- MailMessage msg = new MailMessage();
- msg.To.Add(toName);
- msg.From = new MailAddress(userName, fromName, System.Text.Encoding.UTF8);
- msg.Subject = subject;
- msg.SubjectEncoding = System.Text.Encoding.UTF8;
- msg.Body = content;
- msg.BodyEncoding = System.Text.Encoding.UTF8;
- msg.IsBodyHtml = isHtml;
- msg.Priority = MailPriority.High;
- SmtpClient client = new SmtpClient();
- client.Credentials = new System.Net.NetworkCredential(userName, pwd);
- client.Port =Convert.ToInt32(port);
- client.Host =smtp;
- client.EnableSsl = true;
- try
- {
- client.Send(msg);
- return true;
- }
- catch (System.Net.Mail.SmtpException ex)
- {
- return false;
- }
- }
- }
- }