ASP.NET用Jmail实现邮件群发

1.安装jmail4.3

2.找到jmail.dll(ProgramFiles/Dimac/w3JMail4下)

3.执行ProgramFiles/MicrosoftVisualStudio.NET/FrameworkSDK/Bin/ildasm.exe(可使用VisualStudio.Net2003命令提示),

格式如下:tlbimpc:/ProgramFiles/Dimac/w3JMail4/jmail.dll/out:myJmail.dll/namespace:myJmail

就是我在VisualStudio.Net2005命令提示下编译执行tlbimpc:/ProgramFiles/Dimac/w3JMail4/jmail.dll/out:myJmail.dll/namespace:myJmail
  1. usingSystem;
  2. usingSystem.Data;
  3. usingSystem.Configuration;
  4. usingSystem.Collections;
  5. usingSystem.Web;
  6. usingSystem.Web.Security;
  7. usingSystem.Web.UI;
  8. usingSystem.Web.UI.WebControls;
  9. usingSystem.Web.UI.WebControls.WebParts;
  10. usingSystem.Web.UI.HtmlControls;
  11. usingSystem.Web.Mail;
  12. usingSystem.Web.Util;
  13. usingmyJmail;

  14. usingTool;
  15. usingManager;
  16. usingEntity;

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

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

你可能感兴趣的:(asp.net)