how to send email by jmail?

类别:.NET开发 点击:0 评论:0 推荐:

private void sendmail_jmail()
  {//使用jmail进行邮件发送;需要添加引用jmail.dll
   //jmail.SMTPMailClass mail = new jmail.SMTPMailClass();
   jmail.MessageClass msg = new jmail.MessageClass();
   msg.From = this.tb_from.Text.Trim();
   msg.AddRecipient(this.tb_to.Text.Trim()," Gallon来信","");
   msg.Body= this.tb_mailBody.Text.Trim();
   msg.Subject = " jamil to est";
   msg.MailServerUserName = "邮箱用户名";
   msg.MailServerPassWord = "邮箱密码";
   //msg.AddAttachment(filename, false,"test/html");//发送附件;
   msg.Send(this.tb_smtpserver.Text.Trim(), false);
   msg.Close();

  }

  private void receivemail_jmail()
  {//jmail接收邮件;
   jmail.POP3Class pm = new jmail.POP3Class();
   pm.Connect(this.mail_name.Text.Trim(),this.mail_password.Text.Trim(),this.mail_pop3server.Text.Trim(),110);
   pm.Logging = true;
   pm.DownloadMessages();
   jmail.MessagesClass msgs = (jmail.MessagesClass)pm.Messages;
   for(int i=1;i<msgs.Count;i++)
   {
    //你的信件内容可以这样获得;
    this.mail_sendUser.Text = msgs[i].From;
    this.mail_subject.Text = msgs[i].Subject;
    this.mail_receiveList.Text = msgs[i].RecipientsString;
    this.mail_body.Text = msgs[i].Body;//
    jmail.AttachmentsClass att = (jmail.AttachmentsClass)msgs[i].Attachments;
    for(int j=0;j<att.Count;j++)//附件接收
     att[j].SaveToFile("c:\\"+att[j].Name);
    
   }
   pm.Disconnect();
   
  }

-----------------------------------finished---------------------------------

提示:

注意接口,类的转换,否则无法接收邮件,和附件;

在接收时循环起始为1(附件为0);不知是何故;不会是个ladybug吧;

令外,如果你的jmail.dll在使用中 有问题;

可以用.net的工具 Tlbimp jmail.dll /out:newjmail.dll  /namespace:jmail进行包装;

over

本文地址:http://com.8s8s.com/it/it44331.htm