zoukankan      html  css  js  c++  java
  • c# smtp发送邮件

    public static string SendSMTPEMail(Model.ModelMail_Management modelmail)
    {
        System.Net.Mail.MailAddress from = new System.Net.Mail.MailAddress(modelmail.MailSenderFrom, modelmail.MailSenderFrom);

        System.Net.Mail.MailAddress to = new System.Net.Mail.MailAddress(modelmail.MailSenderTo, modelmail.MailSenderTo);

        System.Net.Mail.MailMessage oMail = new System.Net.Mail.MailMessage(from, to);

        oMail.Subject = modelmail.MailSubject;
        oMail.Body = modelmail.MailBody;

        oMail.IsBodyHtml = true;
        oMail.BodyEncoding = System.Text.Encoding.UTF8;

        //Attachment attachFile = new Attachment("d:\\myinfo.rar");
        //oMail.Attachments.Add(attachFile);

        oMail.Priority = System.Net.Mail.MailPriority.Normal;

        System.Net.ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(ValidateServerCertificate);

        System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient();
        client.Host = modelmail.MailSenderAddress;

        client.Port = Convert.ToInt32(modelmail.MailSenderPort);
        client.Timeout = 100000;
        client.ServicePoint.MaxIdleTime = 1;

        client.UseDefaultCredentials = false;
        client.Credentials = new System.Net.NetworkCredential(modelmail.MailSenderFrom, modelmail.MailSenderPassport);
        client.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;


        try
        {
            client.Send(oMail);
            return "OK";
        }

        catch (System.Net.Mail.SmtpException ex)
        {
            return ex.Message.ToString();
        }
        finally
        {
            oMail.Dispose();
        }
    }

  • 相关阅读:
    正则表达式
    模块初阶
    面向对象的一些理论表述,涉及知识的理解和内置方法
    面向对象的反射 和 特殊内置方法
    面向对象的属性,类方法.静态变量
    面向对象的 多态,
    面向对象的继承属性
    面向对象组合思想的经典题
    面向对象,类名称空间查找顺序 和组合
    jQuery对象与DOM对象之间的转换
  • 原文地址:https://www.cnblogs.com/tatsuya/p/1693404.html
Copyright © 2011-2022 走看看