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

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

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

在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類,文中通過示例代碼介紹的非常詳細(xì)。對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2022-05-05
  • C#使用Tesseract進(jìn)行Ocr識別的方法實(shí)現(xiàn)

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

    本文主要介紹了C#使用Tesseract進(jìn)行Ocr識別的方法實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(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ù)庫的方法,具有一定的參考價(jià)值,有興趣的可以了解一下。
    2017-01-01
  • C#控制Excel Sheet使其自適應(yīng)頁寬與列寬的方法

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

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

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

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

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

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

    c# Struct的一些問題分析

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

    C#解析JSON實(shí)例

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

    C#如何用ThoughtWorks生成二維碼

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

最新評論

内江市| 中江县| 博客| 枣阳市| 车致| 金沙县| 灯塔市| 富顺县| 华宁县| 五寨县| 葫芦岛市| 万山特区| 原平市| 沈阳市| 云林县| 麻城市| 阳西县| 利辛县| 沙洋县| 济宁市| 五常市| 扎兰屯市| 屏东市| 大新县| 隆德县| 凌源市| 海晏县| 梁平县| 和龙市| 崇礼县| 浙江省| 和政县| 汉寿县| 柳林县| 宁武县| 建平县| 米脂县| 读书| 鄱阳县| 桂东县| 全州县|