记录一个发邮件的cs文件

/* ---------------------------------
     *     E-mail 发送接口
     *     调用示例 
     * ---------------------------------
     */ 
    public class webMail
    {
        #region -- declare the variables --
        private string _sender = "";
        private string _account = "";
        private string _password = "";
        private string _server = "";
        private string _subject = "";
        private string _body = "";
        private string _recv = "";
        #endregion

        #region -- declare the interface --
        public string sender
        {
            set
            {
                _sender = value;
            }
        }

        public string sendAccount
        {
            set
            {
                _account = value;
            }
        }

        public string sendPassword
        {
            set
            {
                _password = value;
            }
        }

        public string sendServer
        {
            set
            {
                _server = value;
            }
        }

        public string sendSubject
        {
            set
            {
                _subject = value;
            }
        }

        public string sendBody
        {
            set
            {
                _body = value;
            }
        }

        public string sendRecv
        {
            set
            {
                _recv = value;
            }
        }
        #endregion

        #region string sendMail()
        public string sendMail()
        {
            try
            {
                MailMessage mailMessage = new MailMessage();

                mailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); 
                mailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", _account); 
                mailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", _password); 
                mailMessage.From = _sender;
                mailMessage.To = _recv;
                mailMessage.Subject = _subject;
                mailMessage.Body = _body;

                SmtpMail.SmtpServer = _server;
                SmtpMail.Send(mailMessage);

                return "1";
            }
            catch(Exception ex)
            {
                return ex.Message.ToString();
            }
        }
        #endregion

        #region string testSend(string sender,string subject,string body,string recv)
        public string testSend(string sender,string subject,string body,string recv)
        {
            try
            {
                MailMessage mailMessage = new MailMessage();

                mailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); 
                mailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "kefu@huabaoTrust.com"); 
                mailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "123456"); 
                mailMessage.From = sender;
                mailMessage.To = recv;
                mailMessage.Subject = subject;
                mailMessage.Body = body;

                SmtpMail.SmtpServer = "www.huabaotrust.com";
                SmtpMail.Send(mailMessage);

                return "1";
            }
            catch(Exception ex)
            {
                return ex.Message.ToString();
            }
        }
        #endregion

        #region string sendMail(string sender,string subject,string body,string recv)
        public string sendMail(string sender,string subject,string body,string recv)
        {
            try
            {
                MailMessage mailMessage = new MailMessage();

                mailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); 
                mailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", _account); 
                mailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", _password); 
                mailMessage.From = sender;
                mailMessage.To = recv;
                mailMessage.Subject = subject;
                mailMessage.Body = body;

                SmtpMail.SmtpServer = _server;
                SmtpMail.Send(mailMessage);

                return "1";
            }
            catch(Exception ex)
            {
                return ex.Message.ToString();
            }
        }
        #endregion

        #region string sendMail(string sender,string subject,string body,string recv,string server,string account,string password)
        public string sendMail(string sender,string subject,string body,string recv,string server,string account,string password)
        {
            try
            {
                MailMessage mailMessage = new MailMessage();

                mailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); 
                mailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", account); 
                mailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", password); 
                mailMessage.From = sender;
                mailMessage.To = recv;
                mailMessage.Subject = subject;
                mailMessage.Body = body;

                SmtpMail.SmtpServer = server;
                SmtpMail.Send(mailMessage);

                return "1";
            }
            catch(Exception ex)
            {
                return ex.Message.ToString();
            }
        }
        #endregion
    }

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

发表于

我来说两句

0 条评论
登录 后参与评论

相关文章

来自专栏cs

c sharp 的输入,输入,switch语句。

3055
来自专栏菩提树下的杨过

DataTable排序结果的纠正

默认情况下,即便db中某一列的值是数字,查询出来的DataSet/DataTable里,Column的类型都是String型,所以当用dataTable.Def...

2109
来自专栏.net core新时代

List,DataTable实现行转列的通用方案

  最近在做报表统计方面的需求,涉及到行转列报表。根据以往经验使用SQL可以比较容易完成,这次决定挑战一下直接通过代码方式完成行转列。期间遇到几个问题和用到的新...

2377
来自专栏C# 编程

线程、委托、lambda运算符的简单示例

using System; using System.Collections.Generic; using System.Linq; using System...

2210
来自专栏C# 编程

C#泛型类的简单创建与使用

using System; using System.Collections.Generic; using System.Linq; using System...

2080
来自专栏王磊的博客

HttpWebRequest采集读取网站挂载Cookie的通用方法

Asp.net 版本 HttpWebRequest采集时添加:httpWebRequest.CookieContainer = new CookieContai...

3025
来自专栏跟着阿笨一起玩NET

c# 播放mp3

转载:http://www.cnblogs.com/igrl/archive/2010/03/29/1699975.html

7811
来自专栏c#开发者

asp.net回调javascript

using System; using System.Collections; using System.IO; using System.Text; ...

3285
来自专栏跟着阿笨一起玩NET

C# 4.0命名参数和可选参数

Named And Optional Arguments - 命名参数和可选参数

621
来自专栏程序员与猫

代码小目

标签: 代码片段 日常记录 日常记录的代码片段 1.使用Paralle进行并行计算累加求和的不同形式 public static int ParallelSum...

2177

扫码关注云+社区

领取腾讯云代金券