最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

C#編寫發(fā)送郵件組件

 更新時間:2015年06月17日 11:42:27   投稿:hebedich  
本文給大家分享的是使用C#編寫的發(fā)送郵件的組件,非常的簡單實用,有需要的小伙伴可以參考下。

在MailSetting里的配置好郵件服務(wù)器,然后MailEntity里配置好要發(fā)送的郵件主體,最后使用MailServer里的方法Send發(fā)送郵件

MailEntity.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
 
namespace AutoOutTicket.Mail
{
  public class MailEntity
  {
    public string from;
    public string to;
    public string fromName;
    public string toName;
    public string cc;
    public bool isHtml;
    public string subject;
    public string body;
    public string attach;
  }
}

MailServer.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Mail;
using System.Web;
 
namespace AutoOutTicket.Mail
{
  public class MailServer
  {
    MailEntity _entity = null;
    MailSetting _settings = null;
    public MailServer(MailEntity entity, MailSetting settings)
    {
      this._entity = entity;
      this._settings = settings;
    }
    public bool Send()
    {
      try
      {
        MailMessage message = new MailMessage(_settings.smtpUser, _entity.to);
        message.IsBodyHtml = _entity.isHtml;
        message.Subject = _entity.subject;
        message.Body = _entity.body;
        if (!string.IsNullOrWhiteSpace(_entity.cc))
        {
          message.CC.Add(_entity.cc);
        }
        if (!string.IsNullOrWhiteSpace(_entity.attach))
        {
          Attachment atta=new Attachment(_entity.attach);
          message.Attachments.Add(atta);
        }
 
        SmtpClient client = new SmtpClient(_settings.smtpHost, _settings.smtpPort);
        client.Credentials = new NetworkCredential(_settings.smtpUser, _settings.smtpPass);
 
        client.SendAsync(message, null);
 
        return true;
      }
      catch (Exception)
      {
      }
      return false;
    }
  }
}

MailSetting.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
 
namespace AutoOutTicket.Mail
{
  public class MailSetting
  {
    public string smtpHost = "";
    public int smtpPort;
    public string smtpUser = "";
    public string smtpPass = "";
    public MailSetting()
    {
    }
    public MailSetting(string smtpServer, int smtpPort, string smtpUser, string smtpPass)
    {
      this.smtpHost = smtpServer;
      this.smtpPort = smtpPort;
      this.smtpUser = smtpUser;
      this.smtpPass = smtpPass;
    }
  }
}

以上所述就是本文的全部內(nèi)容了,希望大家能夠喜歡。

相關(guān)文章

  • 淺析C# 結(jié)構(gòu)體struct

    淺析C# 結(jié)構(gòu)體struct

    這篇文章主要介紹了C# 結(jié)構(gòu)體struct 的相關(guān)資料,幫助大家更好的理解和學(xué)習(xí)c#,感興趣的朋友可以了解下
    2020-08-08
  • C#操作注冊表之Registry類

    C#操作注冊表之Registry類

    這篇文章介紹了C#操作注冊表之Registry類,文中通過示例代碼介紹的非常詳細。對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-05-05
  • C#使用Tesseract進行Ocr識別的方法實現(xiàn)

    C#使用Tesseract進行Ocr識別的方法實現(xiàn)

    本文主要介紹了C#使用Tesseract進行Ocr識別的方法實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2022-06-06
  • 詳解C#把DataTable中數(shù)據(jù)一次插入數(shù)據(jù)庫的方法

    詳解C#把DataTable中數(shù)據(jù)一次插入數(shù)據(jù)庫的方法

    本篇文章主要介紹了詳解C#把DataTable中數(shù)據(jù)一次插入數(shù)據(jù)庫的方法,具有一定的參考價值,有興趣的可以了解一下。
    2017-01-01
  • C#控制Excel Sheet使其自適應(yīng)頁寬與列寬的方法

    C#控制Excel Sheet使其自適應(yīng)頁寬與列寬的方法

    這篇文章主要介紹了C#控制Excel Sheet使其自適應(yīng)頁寬與列寬的方法,涉及C#操作Excel的相關(guān)技巧,具有一定參考借鑒價值,需要的朋友可以參考下
    2016-06-06
  • C#連接db2數(shù)據(jù)庫的實現(xiàn)方法

    C#連接db2數(shù)據(jù)庫的實現(xiàn)方法

    本篇文章是對C#連接db2數(shù)據(jù)庫的方法進行了詳細的分析介紹,需要的朋友參考下
    2013-05-05
  • C#使用Gembox.SpreadSheet向Excel寫入數(shù)據(jù)及圖表的實例

    C#使用Gembox.SpreadSheet向Excel寫入數(shù)據(jù)及圖表的實例

    下面小編就為大家分享一篇C#使用Gembox.SpreadSheet向Excel寫入數(shù)據(jù)及圖表的實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2017-12-12
  • c# Struct的一些問題分析

    c# Struct的一些問題分析

    在 C# 中,結(jié)構(gòu)體是值類型數(shù)據(jù)結(jié)構(gòu)。它使得一個單一變量可以存儲各種數(shù)據(jù)類型的相關(guān)數(shù)據(jù)。struct 關(guān)鍵字用于創(chuàng)建結(jié)構(gòu)體。結(jié)構(gòu)體是用來代表一個記錄。
    2021-06-06
  • C#解析JSON實例

    C#解析JSON實例

    這篇文章主要介紹了C#解析JSON的方法,主要采用了C#自帶的JavaScriptSerializer類來實現(xiàn),方法簡單實用,需要的朋友可以參考下
    2014-09-09
  • C#如何用ThoughtWorks生成二維碼

    C#如何用ThoughtWorks生成二維碼

    這篇文章主要介紹了C#如何用ThoughtWorks生成二維碼,文中講解非常細致,幫助大家更好的理解和學(xué)習(xí),感興趣的朋友可以了解下
    2020-08-08

最新評論

苏州市| 剑河县| 孟连| 贵定县| 韶关市| 武夷山市| 田林县| 铜山县| 封开县| 黄陵县| 沂水县| 洛阳市| 称多县| 晋中市| 陈巴尔虎旗| 蛟河市| 仁化县| 无为县| 辽源市| 涿州市| 个旧市| 南木林县| 荃湾区| 扶风县| 东莞市| 泰来县| 曲沃县| 巴青县| 陆河县| 北票市| 渝北区| 康平县| 蕉岭县| 通化县| 南川市| 阳泉市| 乌鲁木齐县| 沁水县| 南汇区| 平顶山市| 凌源市|