程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> .NET實例教程 >> C#發送郵件C/s,B/s通用

C#發送郵件C/s,B/s通用

編輯:.NET實例教程

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Net.Mail;
using System.Net;

/// <summary>
/// EmailPost 的摘要說明
/// </summary>
public class EmailPost
{
 public EmailPost()
 {
  //
  // TODO: 在此處添加構造函數邏輯
  //
 }

    public static string PostEmail(string MailTitle,string MailBody,string RequestEmail)
    {

        string Poster = "[email protected]"; //發送者郵箱地址
        string PosterPwd = "********";//發送者郵箱密碼
        string SmtpHost = "smtp.163.com";  //發送郵件服務器
        string getstr = "";
        MailMessage mailmsg = new MailMessage();
        mailmsg.From = new MailAddress(Poster);  //定義發件人
        mailmsg.To.Add(RequestEmail); //添加收件人
        mailmsg.Subject = MailTitle;  //郵件標題
        mailmsg.Body =MailBody;  //郵件內容
        //return SendEmail(mailmsg);

        SmtpClient smtpClient = new SmtpClIEnt();
        //smtpClIEnt.EnableSsl = true;
        smtpClIEnt.Host = SmtpHost;
        //smtpClIEnt.Port = 465;
        smtpClIEnt.Credentials = new NetworkCredential(Poster, PosterPwd);
        try
        {
            smtpClIEnt.Send(mailmsg);
            getstr += "發送成功";
        }
        catch
        {
            getstr += "發送失敗";
        }
        return getstr;

    }


}

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved