ASP.NET用Jmail实现邮件群发

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

就是我在Visual Studio .Net 2005命令提示下编译执行 tlbimp c:/Program Files/Dimac/w3JMail4/jmail.dll /out:myJmail.dll /namespace:myJmail
  1. using System;
  2. using System.Data;
  3. using System.Configuration;
  4. using System.Collections;
  5. using System.Web;
  6. using System.Web.Security;
  7. using System.Web.UI;
  8. using System.Web.UI.WebControls;
  9. using System.Web.UI.WebControls.WebParts;
  10. using System.Web.UI.HtmlControls;
  11. using System.Web.Mail;
  12. using System.Web.Util;
  13. using myJmail;

  14. using Tool;
  15. using Manager;
  16. using Entity;

  17. public partial class UserControls_Jmaill : System.Web.UI.UserControl
  18. {
  19.     string strCurrentPath = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString();
  20.     protected void Page_Load(object sender, EventArgs e)
  21.     {
  22.     }
  23.     protected void btnSend_Click(object sender, EventArgs e)
  24.     {
  25.         try
  26.         {
  27.             this.lblTitle.Text = "发送邮件控件";
  28.   
  29.             myJmail.Message Jmail = new myJmail.Message();
  30.             DateTime t = DateTime.Now;
  31.             String Subject = this.txtTitle.Text;
  32.             String body = this.txtContent.Text;
  33.             string FromEmail = this.txtFormEmail.Text.Trim();//你的email
  34.             String ToEmail = this.txtToEmail.Text;//对方的email
  35.             String AddAttachment = this.FileUploadSubject.PostedFile.FileName;
  36.             //Silent属性:如果设置为true,JMail不会抛出例外错误. JMail. Send( () 会根据操作结果返回true或false
  37.             Jmail.Silent = true;
  38.             //Jmail创建的日志,前提loging属性设置为true
  39.             Jmail.Logging = true;
  40.             //字符集,缺省为"US-ASCII"
  41.             Jmail.Charset = "GB2312";
  42.             //信件的contentype. 缺省是"text/plain") : 字符串如果你以HTML格式发送邮件, 改为"text/html"即可。
  43.           //  Jmail.ContentType = "text/html";
  44.             ToEmail = ToEmail.Replace("/n""").Replace(" """);
  45.             string[] str = ToEmail.Split(’,’);

  46.             for (int i = 0; i < str.Length; i++)
  47.             {
  48.                 //添加收件人
  49.                 Jmail.AddRecipient(str[i], """");
  50.                 
  51.                 Jmail.From = FromEmail;
  52.                 //发件人邮件用户名
  53.                 Jmail.MailServerUserName = FromEmail;
  54.                 //发件人邮件密码
  55.                 Jmail.MailServerPassWord = "";//FromEmail邮箱的登陆密码
  56.                 //设置邮件标题
  57.                 Jmail.Subject = Subject;
  58.                 //  邮件添加附件,(多附件的话,可以再加一条Jmail.AddAttachment( "c://test.jpg",true,null);)就可以搞 定了。[注]:加了附件,讲把上面的Jmail.ContentType="text/html";删掉。否则会在邮件里出现乱码。
  59.                 Jmail.AddAttachment(AddAttachment, truenull);
  60.                 //邮件内容
  61.                 Jmail.Body = body + t.ToString();
  62.                 //加密文件
  63.                 //Jmail.PGPEncrypt = true;
  64.                 //Jmail发送的方法
  65.                 Jmail.Send("smtp.163.com"false);
  66.                 Jmail.ClearAttachments();
  67.                 Jmail.ClearRecipients();
  68.             }
  69.             Jmail.Close();
  70.         }
  71.         catch (Exception ex)
  72.         {
  73.             this.lblMessage.Text = ex.Message;
  74.         }
  75.     }
  76.  
  77. }
 

你可能感兴趣的:(ASP.NET用Jmail实现邮件群发)