zoukankan      html  css  js  c++  java
  • vs2003和vs2005两种不同的发送email方式

    vs2003
    public static bool SendMail(string from, string to, string subject, string body, string smtpServer, string userName, string password, ref string result)
        
    {
            MailMessage mailMsg 
    = new MailMessage();
            
    //设置正文格式
            mailMsg.BodyFormat = MailFormat.Html;
            
    //设置收件人的邮件地址
            mailMsg.To = to;
            
    //设置发送者的邮件地址
            mailMsg.From = from;
            
    //设置邮件主题
            mailMsg.Subject = subject;
            
    //设置邮件内容
            mailMsg.Body = body;
            
    //设置支持服务器验证
            mailMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate""1");
            
    //设置用户名
            mailMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", userName);
            
    //设置用户密码
            mailMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", password);
            
    try
            
    {
                
    //设置发送邮件服务器            
                SmtpMail.SmtpServer = smtpServer;
                
    //发送邮件
                SmtpMail.Send(mailMsg);
                
    return true;
            }

            
    catch (Exception err)
            
    {
                result 
    = err.Message.ToString();
                
    return false;
            }

        }

    vs2005
    public void SendEmail()
        
    {
            System.Net.Mail.SmtpClient client 
    = new System.Net.Mail.SmtpClient("smtp.163.com");
            client.UseDefaultCredentials 
    = false;
            client.Credentials 
    = new System.Net.NetworkCredential("from@163.com""888999");
            client.DeliveryMethod 
    = SmtpDeliveryMethod.Network;
            System.Net.Mail.MailMessage message 
    = new System.Net.Mail.MailMessage("from@163.com""to@gmail.com""subject ""body");
            message.BodyEncoding 
    = System.Text.Encoding.UTF8;
            message.IsBodyHtml 
    = true;
            client.Send(message);        
        }
  • 相关阅读:
    ASP.NET Web API 控制器执行过程(一)
    ASP.NET Web API 控制器创建过程(二)
    ASP.NET Web API 控制器创建过程(一)
    ASP.NET Web API WebHost宿主环境中管道、路由
    ASP.NET Web API Selfhost宿主环境中管道、路由
    ASP.NET Web API 管道模型
    ASP.NET Web API 路由对象介绍
    ASP.NET Web API 开篇示例介绍
    ASP.NET MVC 视图(五)
    ASP.NET MVC 视图(四)
  • 原文地址:https://www.cnblogs.com/ami/p/828299.html
Copyright © 2011-2022 走看看