首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >记录一个发邮件的cs文件

记录一个发邮件的cs文件

作者头像
用户1172164
发布2018-01-16 14:43:28
4200
发布2018-01-16 14:43:28
举报
/* ---------------------------------
     *     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
    }
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2007-03-19 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档