asp.net利用jmail發送郵件

來源:互聯網
上載者:User

1.安裝jmail4.3

2.找到jmail.dll(Program Files\Dimac\w3JMail4下)

3.執行Program Files\Microsoft Visual Studio .NET\FrameworkSDK\Bin\ildasm.exe(可使用Visual Studio .Net 2003 命令提示),

格式如下:tlbimp c:\Program Files\Dimac\w3JMail4\jmail.dll /out:myJmail.dll /namespace:myJmail

產生myJmail.dll後,copy到web的根目錄的bin目錄。在ASP.Net頁面中,用這個方法引用:Jmail.aspx

將myjmail.dll引用到工程中

private void Button1_Click(object sender, System.EventArgs e)
  {
   
   jmail.Message  Jmail=new jmail.Message();

   DateTime t=DateTime.Now;  
   String Subject=" From EMail .net";  
   String body="你好科學12:15";
   String FromEmail="XXX@163.com";  
   String ToEmail="xxxx@163.com";
   //Silent屬性:如果設定為true,JMail不會拋出例外錯誤. JMail. Send( () 會根據操作結果返回true或false
   Jmail.Silent=true;
   //Jmail建立的日誌,前提loging屬性設定為true
   Jmail.Logging=true;
   //字元集,預設為"US-ASCII"
   Jmail.Charset="GB2312";
   //信件的contentype. 預設是"text/plain") : 字串如果你以HTML格式發送郵件, 改為"text/html"即可。
   Jmail.ContentType="text/html";
   //添加收件者
   Jmail.AddRecipient(ToEmail,"","");
   Jmail.From=FromEmail;
   //寄件者郵件使用者名
   Jmail.MailServerUserName="ljt21" ;
   //寄件者郵件密碼
   Jmail.MailServerPassWord="****" ;
   //設定郵件標題
   Jmail.Subject=Subject;
   //郵件添加附件,(多附件的話,可以再加一條Jmail.AddAttachment( "c:\\test.jpg",true,null);)就可以搞定了。[注]:加了附件,講把上面的Jmail.ContentType="text/html";刪掉。否則會在郵件裡出現亂碼。
   Jmail.AddAttachment( "c:\\test.jpg",true,null);
   //郵件內容
   Jmail.Body=body+t.ToString();
   //Jmail發送的方法
   Jmail.Send("smtp.163.com",false);
   Jmail.Close() ;
  }

本文來自CSDN部落格,轉載請標明出處:http://blog.csdn.net/leekeyshaw/archive/2006/03/29/642934.aspx

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.