Send message class C #

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Mail;

namespace ExtractAbnormalUsers
{
    class MailSend
    {
        public static bool send(string content,string to,string from,string fromname,string topic,string usr,string pwd)
        {
            //MailAddress 发送邮件
            MailMessage msg = new MailMessage();
            string mailContent = content;
            msg.To.Add(to);//收件人
            //发件人信息
            msg.From = new MailAddress(from, fromname, System.Text.Encoding.UTF8);
            msg.Subject = topic;
            msg.SubjectEncoding = System.Text.Encoding.UTF8;
            msg.Body = mailContent;
            msg.BodyEncoding = System.Text.Encoding.UTF8;
            msg.IsBodyHtml = true;
            msg.Priority = MailPriority.High;//优先级 
            SmtpClient client = new SmtpClient();
            client.Credentials = new System.Net.NetworkCredential(usr, pwd);
            client.Port = 587;//gmail的端口号
            client.Host = "mail.hundsun.com";
            client.EnableSsl = true;
            client.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
            object userState = msg;
            try
            {
                client.Send(msg);
                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }
    }
}

Published 48 original articles · won praise 3 · views 20000 +

Guess you like

Origin blog.csdn.net/chscomfaner/article/details/82803899