導航:首頁 > 編程語言 > java郵件回執

java郵件回執

發布時間:2022-09-28 10:55:25

javamail如何讀取回執信息

請在OUTLOOK中選中工具再選中選項,打開選項後出現首選參數欄選中電子郵件選項再選擇跟蹤選項,內面有具體的設置選項,可測試一下即可

Ⅱ java發送郵件程序如何驗證郵件是否發送失敗

public boolean sendout()
{
try
{
mimeMessage.setContent(mp);
mimeMessage.saveChanges();
Session mailSession = Session.getInstance(props, null);
Transport transport = mailSession.getTransport("smtp");
transport.connect(hostname, username, password);
transport.sendMessage(mimeMessage, mimeMessage.getRecipients(javax.mail.Message.RecipientType.TO));
transport.close();
}
catch(Exception e)
{

e.printStackTrace();
return false;
}
return true;
}

捕獲異常判斷

Ⅲ java mail 問題:系統給用戶發送了提醒信息,怎麼在系統後台獲取用戶的回執信息。

沒有做過,但是經常看到這種例子,個人認為可以這么做:
按鈕 就是一個<a>連接,直接向一個servlet 發請求,帶上用戶id 和標志就可以了
如果讓我實現,思路就是這樣

Ⅳ javamail接收郵件怎麼解析內容

package com.ghy.util;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Properties;

import javax.mail.BodyPart;
import javax.mail.Flags;
import javax.mail.Folder;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Multipart;

import javax.mail.Part;
import javax.mail.Session;
import javax.mail.Store;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeUtility;

public class PraseMimeMessage{
private MimeMessage mimeMessage=null;
private String saveAttachPath="";//附件下載後的存放目錄
private StringBuffer bodytext=new StringBuffer();
//存放郵件內容的StringBuffer對象
private String dateformat="yy-MM-ddHH:mm";//默認的日前顯示格式
/**
*構造函數,初始化一個MimeMessage對象
*/
public PraseMimeMessage() {
}
public PraseMimeMessage(MimeMessage mimeMessage) {
this.mimeMessage=mimeMessage;
}
public void setMimeMessage(MimeMessage mimeMessage){
this.mimeMessage=mimeMessage;
}
/**
*獲得發件人的地址和姓名
*/
public String getFrom1()throws Exception{
InternetAddress address[]=(InternetAddress[])mimeMessage.getFrom();
String from=address[0].getAddress();
if(from==null){
from="";
}
String personal=address[0].getPersonal();
if(personal==null){
personal="";
}
String fromaddr=personal+"<"+from+">";
return fromaddr;
}
/**
*獲得郵件的收件人,抄送,和密送的地址和姓名,根據所傳遞的參數的不同
*"to"----收件人"cc"---抄送人地址"bcc"---密送人地址
* @throws Exception */
public String getMailAddress(String type){
String mailaddr="";
try {
String addtype=type.toUpperCase();
InternetAddress []address=null;
if(addtype.equals("TO")||addtype.equals("CC")||addtype.equals("BBC")){
if(addtype.equals("TO")){
address=(InternetAddress[])mimeMessage.getRecipients(Message.RecipientType.TO);
}
else if(addtype.equals("CC")){
address=(InternetAddress[])mimeMessage.getRecipients(Message.RecipientType.CC);
}
else{
address=(InternetAddress[])mimeMessage.getRecipients(Message.RecipientType.BCC);
}
if(address!=null){
for (int i = 0; i < address.length; i++) {
String email=address[i].getAddress();
if(email==null)email="";
else{
email=MimeUtility.decodeText(email);
}
String personal=address[i].getPersonal();
if(personal==null)personal="";
else{
personal=MimeUtility.decodeText(personal);
}
String compositeto=personal+"<"+email+">";
mailaddr+=","+compositeto;
}
mailaddr=mailaddr.substring(1);
}
}
else{
}
} catch (Exception e) {
// TODO: handle exception
}
return mailaddr;
}
/**
*獲得郵件主題
*/
public String getSubject()
{
String subject="";
try {
subject=MimeUtility.decodeText(mimeMessage.getSubject());
if(subject==null)subject="";
} catch (Exception e) {
// TODO: handle exception
}
return subject;
}
/**
*獲得郵件發送日期
*/
public String getSendDate()throws Exception{
Date senddate=mimeMessage.getSentDate();
SimpleDateFormat format=new SimpleDateFormat(dateformat);
return format.format(senddate);
}
/**
*解析郵件,把得到的郵件內容保存到一個StringBuffer對象中,解析郵件
*主要是根據MimeType類型的不同執行不同的操作,一步一步的解析
*/
public void getMailContent(Part part)throws Exception{
String contenttype=part.getContentType();
int nameindex=contenttype.indexOf("name");
boolean conname=false;
if(nameindex!=-1)conname=true;
if(part.isMimeType("text/plain")&&!conname){
bodytext.append((String)part.getContent());
}else if(part.isMimeType("text/html")&&!conname){
bodytext.append((String)part.getContent());
}
else if(part.isMimeType("multipart/*")){
Multipart multipart=(Multipart)part.getContent();
int counts=multipart.getCount();
for(int i=0;i<counts;i++){
getMailContent(multipart.getBodyPart(i));
}
}else if(part.isMimeType("message/rfc822")){
getMailContent((Part)part.getContent());
}
else{}
}
/**
*獲得郵件正文內容
*/
public String getBodyText(){
return bodytext.toString();
}
/**
*判斷此郵件是否需要回執,如果需要回執返回"true",否則返回"false"

* @throws MessagingException */
public boolean getReplySign() throws MessagingException{
boolean replysign=false;
String needreply[]=mimeMessage.getHeader("Disposition-Notification-To");
if(needreply!=null){
replysign=true;
}
return replysign;
}
/**
*獲得此郵件的Message-ID
* @throws MessagingException */
public String getMessageId() throws MessagingException{
return mimeMessage.getMessageID();
}

/**
*【判斷此郵件是否已讀,如果未讀返回返回false,反之返回true】
* @throws MessagingException */
public boolean isNew() throws MessagingException{
boolean isnew =false;
Flags flags=((Message)mimeMessage).getFlags();
Flags.Flag[]flag=flags.getSystemFlags();
for (int i = 0; i < flag.length; i++) {
if(flag[i]==Flags.Flag.SEEN){
isnew=true;
break;
}
}
return isnew;
}
/**
*判斷此郵件是否包含附件
* @throws MessagingException */
public boolean isContainAttach(Part part) throws Exception{
boolean attachflag=false;
String contentType=part.getContentType();
if(part.isMimeType("multipart/*")){
Multipart mp=(Multipart)part.getContent();
//獲取附件名稱可能包含多個附件
for(int j=0;j<mp.getCount();j++){
BodyPart mpart=mp.getBodyPart(j);
String disposition=mpart.getDescription();
if((disposition!=null)&&((disposition.equals(Part.ATTACHMENT))||(disposition.equals(Part.INLINE)))){
attachflag=true;
}else if(mpart.isMimeType("multipart/*")){
attachflag=isContainAttach((Part)mpart);
}else{
String contype=mpart.getContentType();
if(contype.toLowerCase().indexOf("application")!=-1) attachflag=true;
if(contype.toLowerCase().indexOf("name")!=-1) attachflag=true;
}
}
}else if(part.isMimeType("message/rfc822")){
attachflag=isContainAttach((Part)part.getContent());
}
return attachflag;
}
/**
*【保存附件】
* @throws Exception
* @throws IOException
* @throws MessagingException
* @throws Exception */
public void saveAttachMent(Part part) throws Exception {
String fileName="";
if(part.isMimeType("multipart/*")){
Multipart mp=(Multipart)part.getContent();
for(int j=0;j<mp.getCount();j++){
BodyPart mpart=mp.getBodyPart(j);
String disposition=mpart.getDescription();
if((disposition!=null)&&((disposition.equals(Part.ATTACHMENT))||(disposition.equals(Part.INLINE)))){
fileName=mpart.getFileName();
if(fileName.toLowerCase().indexOf("GBK")!=-1){
fileName=MimeUtility.decodeText(fileName);
}
saveFile(fileName,mpart.getInputStream());
}
else if(mpart.isMimeType("multipart/*")){
fileName=mpart.getFileName();
}
else{
fileName=mpart.getFileName();
if((fileName!=null)){
fileName=MimeUtility.decodeText(fileName);
saveFile(fileName,mpart.getInputStream());
}
}
}
}
else if(part.isMimeType("message/rfc822")){
saveAttachMent((Part)part.getContent());
}
}
/**
*【設置附件存放路徑】
*/
public void setAttachPath(String attachpath){
this.saveAttachPath=attachpath;
}

/**
*【設置日期顯示格式】
*/
public void setDateFormat(String format){
this.dateformat=format;
}

/**
*【獲得附件存放路徑】
*/

public String getAttachPath()
{
return saveAttachPath;
}
/**
*【真正的保存附件到指定目錄里】
*/
private void saveFile(String fileName,InputStream in)throws Exception{
String osName=System.getProperty("os.name");
String storedir=getAttachPath();
String separator="";
if(osName==null)osName="";
if(osName.toLowerCase().indexOf("win")!=-1){
//如果是window 操作系統
separator="/";
if(storedir==null||storedir.equals(""))storedir="c:\tmp";
}
else{
//如果是其他的系統
separator="/";
storedir="/tmp";
}
File strorefile=new File(storedir+separator+fileName);
BufferedOutputStream bos=null;
BufferedInputStream bis=null;
try {
bos=new BufferedOutputStream(new FileOutputStream(strorefile));
bis=new BufferedInputStream(in);
int c;
while((c=bis.read())!=-1){
bos.write(c);
bos.flush();
}
} catch (Exception e) {
// TODO: handle exception
}finally{
bos.close();
bis.close();
}
}
/**
*PraseMimeMessage類測試

* @throws Exception */
public static void main(String[] args) throws Exception {
String host="pop3.sina.com.cn";
String username="guohuaiyong70345";
String password="071120";
Properties props=new Properties();
Session session=Session.getDefaultInstance(props,null);
Store store=session.getStore("pop3");
store.connect(host,username,password);
Folder folder=store.getFolder("INBOX");
folder.open(Folder.READ_ONLY);
Message message[]=folder.getMessages();
PraseMimeMessage pmm=null;
for (int i = 0; i < message.length; i++) {
System.out.println("****************************************第"+(i+1)+"封郵件**********************************");
pmm=new PraseMimeMessage((MimeMessage)message[i]);
System.out.println("主題 :"+pmm.getSubject());
pmm.setDateFormat("yy年MM月dd日 HH:mm");
System.out.println("發送時間 :"+pmm.getSendDate());
System.out.println("是否回執 :"+pmm.getReplySign());
System.out.println("是否包含附件 :"+pmm.isContainAttach((Part)message[i]));
System.out.println("發件人 :"+pmm.getFrom1());
System.out.println("收件人 :"+pmm.getMailAddress("TO"));
System.out.println("抄送地址 :"+pmm.getMailAddress("CC"));
System.out.println("密送地址 :"+pmm.getMailAddress("BCC"));
System.out.println("郵件ID :"+i+":"+pmm.getMessageId());
pmm.getMailContent((Part)message[i]); //根據內容的不同解析郵件
pmm.setAttachPath("c:/tmp/mail"); //設置郵件附件的保存路徑
pmm.saveAttachMent((Part)message[i]); //保存附件
System.out.println("郵件正文 :"+pmm.getBodyText());
System.out.println("*********************************第"+(i+1)+"封郵件結束*************************************");
}
}
}

Ⅳ javamail發送郵件怎麼確定郵件是否成功了,會有回執信息返回嗎,send()方法返回值是空。

通過捕捉異常來判斷,看一下我寫的代碼
try{
transport.connect(smtp, username, password);
transport.sendMessage(message, message.getAllRecipients());
transport.close();
out.print("<script charset='utf-8'>alert('郵件發送已成功!');window.history.go(-1);</script>");
} catch (MessagingException e) {
// TODO Auto-generated catch block
out.print("<script charset='utf-8'>alert('郵件發送失敗!');window.history.go(-1);</script>");
}
這樣就可以判斷是否發送成功了。
我最近也在做javamail的項目,歡迎來一起討論。

Ⅵ Java做滿意度評價 和列印回執單怎麼寫

用幾個常量表示評價的等級,根據評價者的按鍵選擇,顯示相應的評價級別。並最終列印出來即可

Ⅶ javamail收發信件時,伺服器,收發方的名稱應該怎樣設置才有效呢

package com.gwxc.hz.mail.demo;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Properties;

import javax.mail.BodyPart;
import javax.mail.Flags;
import javax.mail.Folder;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Multipart;
import javax.mail.NoSuchProviderException;
import javax.mail.Part;
import javax.mail.Session;
import javax.mail.Store;
import javax.mail.URLName;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeUtility;

public class ReciveOneMail {

/**
* 有一封郵件就需要建立一個ReciveMail對象
*/
private MimeMessage mimeMessage = null;
private String saveAttachPath = ""; // 附件下載後的存放目錄
private StringBuffer bodytext = new StringBuffer();// 存放郵件內容
private String dateformat = "yy-MM-dd HH:mm"; // 默認的日前顯示格式

public ReciveOneMail(MimeMessage mimeMessage) {
this.mimeMessage = mimeMessage;
}

public void setMimeMessage(MimeMessage mimeMessage) {
this.mimeMessage = mimeMessage;
}

/**
* 獲得發件人的地址和姓名
*/
public String getFrom() throws Exception {
InternetAddress address[] = (InternetAddress[]) mimeMessage.getFrom();
String from = address[0].getAddress();
if (from == null)
from = "";
String personal = address[0].getPersonal();
if (personal == null)
personal = "";
String fromaddr = personal + "<" + from + ">";
return fromaddr;
}

/**
* 獲得郵件的收件人,抄送,和密送的地址和姓名,根據所傳遞的參數的不同 "to"----收件人 "cc"---抄送人地址 "bcc"---密送人地址
*/
public String getMailAddress(String type) throws Exception {
String mailaddr = "";
String addtype = type.toUpperCase();
InternetAddress[] address = null;
if (addtype.equals("TO") || addtype.equals("CC")
|| addtype.equals("BCC")) {
if (addtype.equals("TO")) {
address = (InternetAddress[]) mimeMessage
.getRecipients(Message.RecipientType.TO);
} else if (addtype.equals("CC")) {
address = (InternetAddress[]) mimeMessage
.getRecipients(Message.RecipientType.CC);
} else {
address = (InternetAddress[]) mimeMessage
.getRecipients(Message.RecipientType.BCC);
}
if (address != null) {
for (int i = 0; i < address.length; i++) {
String email = address[i].getAddress();
if (email == null)
email = "";
else {
email = MimeUtility.decodeText(email);
}
String personal = address[i].getPersonal();
if (personal == null)
personal = "";
else {
personal = MimeUtility.decodeText(personal);
}
String compositeto = personal + "<" + email + ">";
mailaddr += "," + compositeto;
}
mailaddr = mailaddr.substring(1);
}
} else {
throw new Exception("Error emailaddr type!");
}
return mailaddr;
}

/**
* 獲得郵件主題
*/
public String getSubject() throws MessagingException {
String subject = "";
try {
subject = MimeUtility.decodeText(mimeMessage.getSubject());
if (subject == null)
subject = "";
} catch (Exception exce) {
}
return subject;
}

/**
* 獲得郵件發送日期
*/
public String getSentDate() throws Exception {
Date sentdate = mimeMessage.getSentDate();
SimpleDateFormat format = new SimpleDateFormat(dateformat);
return format.format(sentdate);
}

/**
* 獲得郵件正文內容
*/
public String getBodyText() {
return bodytext.toString();
}

/**
* 解析郵件,把得到的郵件內容保存到一個StringBuffer對象中,解析郵件 主要是根據MimeType類型的不同執行不同的操作,一步一步的解析
*/
public void getMailContent(Part part) throws Exception {
String contenttype = part.getContentType();
int nameindex = contenttype.indexOf("name");
boolean conname = false;
if (nameindex != -1)
conname = true;
System.out.println("CONTENTTYPE: " + contenttype);
if (part.isMimeType("text/plain") && !conname) {
bodytext.append((String) part.getContent());
} else if (part.isMimeType("text/html") && !conname) {
bodytext.append((String) part.getContent());
} else if (part.isMimeType("multipart/*")) {
Multipart multipart = (Multipart) part.getContent();
int counts = multipart.getCount();
for (int i = 0; i < counts; i++) {
getMailContent(multipart.getBodyPart(i));
}
} else if (part.isMimeType("message/rfc822")) {
getMailContent((Part) part.getContent());
} else {
}
}

/**
* 判斷此郵件是否需要回執,如果需要回執返回"true",否則返回"false"
*/
public boolean getReplySign() throws MessagingException {
boolean replysign = false;
String needreply[] = mimeMessage
.getHeader("Disposition-Notification-To");
if (needreply != null) {
replysign = true;
}
return replysign;
}

/**
* 獲得此郵件的Message-ID
*/
public String getMessageId() throws MessagingException {
return mimeMessage.getMessageID();
}

/**
* 【判斷此郵件是否已讀,如果未讀返回返回false,反之返回true】
*/
public boolean isNew() throws MessagingException {
boolean isnew = false;
Flags flags = ((Message) mimeMessage).getFlags();
Flags.Flag[] flag = flags.getSystemFlags();
System.out.println("flags's length: " + flag.length);
for (int i = 0; i < flag.length; i++) {
if (flag[i] == Flags.Flag.SEEN) {
isnew = true;
System.out.println("seen Message.......");
break;
}
}
return isnew;
}

/**
* 判斷此郵件是否包含附件
*/
public boolean isContainAttach(Part part) throws Exception {
boolean attachflag = false;
String contentType = part.getContentType();
if (part.isMimeType("multipart/*")) {
Multipart mp = (Multipart) part.getContent();
for (int i = 0; i < mp.getCount(); i++) {
BodyPart mpart = mp.getBodyPart(i);
String disposition = mpart.getDisposition();
if ((disposition != null)
&& ((disposition.equals(Part.ATTACHMENT)) || (disposition
.equals(Part.INLINE))))
attachflag = true;
else if (mpart.isMimeType("multipart/*")) {
attachflag = isContainAttach((Part) mpart);
} else {
String contype = mpart.getContentType();
if (contype.toLowerCase().indexOf("application") != -1)
attachflag = true;
if (contype.toLowerCase().indexOf("name") != -1)
attachflag = true;
}
}
} else if (part.isMimeType("message/rfc822")) {
attachflag = isContainAttach((Part) part.getContent());
}
return attachflag;
}

/**
* 【保存附件】
*/
public void saveAttachMent(Part part) throws Exception {
String fileName = "";
if (part.isMimeType("multipart/*")) {
Multipart mp = (Multipart) part.getContent();
for (int i = 0; i < mp.getCount(); i++) {
BodyPart mpart = mp.getBodyPart(i);
String disposition = mpart.getDisposition();
if ((disposition != null)
&& ((disposition.equals(Part.ATTACHMENT)) || (disposition
.equals(Part.INLINE)))) {
fileName = mpart.getFileName();
if (fileName.toLowerCase().indexOf("gb2312") != -1) {
fileName = MimeUtility.decodeText(fileName);
}
saveFile(fileName, mpart.getInputStream());
} else if (mpart.isMimeType("multipart/*")) {
saveAttachMent(mpart);
} else {
fileName = mpart.getFileName();
if ((fileName != null)
&& (fileName.toLowerCase().indexOf("GB2312") != -1)) {
fileName = MimeUtility.decodeText(fileName);
saveFile(fileName, mpart.getInputStream());
}
}
}
} else if (part.isMimeType("message/rfc822")) {
saveAttachMent((Part) part.getContent());
}
}

/**
* 【設置附件存放路徑】
*/

public void setAttachPath(String attachpath) {
this.saveAttachPath = attachpath;
}

/**
* 【設置日期顯示格式】
*/
public void setDateFormat(String format) throws Exception {
this.dateformat = format;
}

/**
* 【獲得附件存放路徑】
*/
public String getAttachPath() {
return saveAttachPath;
}

/**
* 【真正的保存附件到指定目錄里】
*/
private void saveFile(String fileName, InputStream in) throws Exception {
String osName = System.getProperty("os.name");
String storedir = getAttachPath();
String separator = "";
if (osName == null)
osName = "";
if (osName.toLowerCase().indexOf("win") != -1) {
separator = "\\";
if (storedir == null || storedir.equals(""))
storedir = "c:\\tmp";
} else {
separator = "/";
storedir = "/tmp";
}
File storefile = new File(storedir + separator + fileName);
System.out.println("storefile's path: " + storefile.toString());
// for(int i=0;storefile.exists();i++){
// storefile = new File(storedir+separator+fileName+i);
// }
BufferedOutputStream bos = null;
BufferedInputStream bis = null;
try {
bos = new BufferedOutputStream(new FileOutputStream(storefile));
bis = new BufferedInputStream(in);
int c;
while ((c = bis.read()) != -1) {
bos.write(c);
bos.flush();
}
} catch (Exception exception) {
exception.printStackTrace();
throw new Exception("文件保存失敗!");
} finally {
bos.close();
bis.close();
}
}

public static void main(String[] args) throws Exception {
Properties props = System.getProperties();
props.put("mail.smtp.host", "smtp.163.com");
props.put("mail.smtp.auth", "true");
Session session = Session.getDefaultInstance(props, null);
URLName urln = new URLName("pop3", "pop3.163.com", 110, null,
"dt_cj2004", "abcdefghij");
Store store = session.getStore(urln);
store.connect();

Folder folder = store.getFolder("spool");
//Folder folder = store.getFullName();

folder.open(Folder.READ_ONLY);
//System.out.println(folder.getNewMessageCount());

Message message[] = folder.getMessages();
System.out.println("Messages's length: " + message.length);
ReciveOneMail pmm = null;
/*

for (int i = 0; i < message.length; i++) {
System.out.println("======================");
pmm = new ReciveOneMail((MimeMessage) message[i]);
System.out
.println("Message " + i + " subject: " + pmm.getSubject());
System.out.println("Message " + i + " sentdate: "
+ pmm.getSentDate());
System.out.println("Message " + i + " replysign: "
+ pmm.getReplySign());
System.out.println("Message " + i + " hasRead: " + pmm.isNew());
System.out.println("Message " + i + " containAttachment: "
+ pmm.isContainAttach((Part) message[i]));
System.out.println("Message " + i + " form: " + pmm.getFrom());
System.out.println("Message " + i + " to: "
+ pmm.getMailAddress("to"));
System.out.println("Message " + i + " cc: "
+ pmm.getMailAddress("cc"));
System.out.println("Message " + i + " bcc: "
+ pmm.getMailAddress("bcc"));
pmm.setDateFormat("yy年MM月dd日 HH:mm");
System.out.println("Message " + i + " sentdate: "
+ pmm.getSentDate());
System.out.println("Message " + i + " Message-ID: "
+ pmm.getMessageId());
// 獲得郵件內容===============
pmm.getMailContent((Part) message[i]);
System.out.println("Message " + i + " bodycontent: \r\n"
+ pmm.getBodyText());
pmm.setAttachPath("c:\\");
pmm.saveAttachMent((Part) message[i]);
}
*/
}
}

package com.gwxc.hz.mail.demo;

import java.util.Properties;

import javax.activation.DataHandler;
import javax.activation.FileDataSource;
import javax.mail.BodyPart;
import javax.mail.Message;
import javax.mail.Multipart;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;

public class MyMailTest {

/**
* @param args
*/
public static void main(String[] args) throws Exception {

// 會話===========================
Properties props = System.getProperties();
props.put("mail.smtp.host", "smtp.163.com");
props.put("mail.smtp.auth", "true");// 需要驗證
Session session = Session.getDefaultInstance(props, null);

// msg 設置=======================
MimeMessage mimeMsg = new MimeMessage(session);

// 設置標題
mimeMsg.setSubject("標題test");

// 設置內容----begin
Multipart mp = new MimeMultipart();

// 添加文本
BodyPart bp1 = new MimeBodyPart();
bp1.setContent("文本內容", "text/html;charset=GB2312");
mp.addBodyPart(bp1);

// 添加附件
BodyPart bp2 = new MimeBodyPart();
FileDataSource fileds = new FileDataSource("c:\\boot.ini");
bp2.setDataHandler(new DataHandler(fileds));
bp2.setFileName(fileds.getName());
mp.addBodyPart(bp2);

mimeMsg.setContent(mp);
// 設置內容----end

mimeMsg.setFrom(new InternetAddress("[email protected]"));
mimeMsg.setRecipients(Message.RecipientType.TO, InternetAddress
.parse("[email protected]"));
mimeMsg.saveChanges();

// 傳輸==================================
Transport transport = session.getTransport("smtp");
transport.connect((String) props.get("mail.smtp.host"),
"xiangzhengyan", "pass");
transport.sendMessage(mimeMsg, mimeMsg
.getRecipients(Message.RecipientType.TO));
transport.close();
}

}

Ⅷ javaMail判斷收到的郵件是否是回執郵件

我們測試一下,標題是:測試回執

需要回執的原始郵件
Message-ID: <[email protected]>
X-mailer: Foxmail 6, 10, 201, 20 [cn]
Disposition-Notification-To: "php2000" <[email protected]>
Subject: =?gb2312?B?suLK1LvY1rQ=?=

收到的信息
Message-ID: <16446385.5181199249234389.JavaMail.SYSTEM@svctag-hj8w32x>
Subject: =?gb2312?B?suLK1LvY1rQ=?=
MIME-Version: 1.0
X-UserIsAuth: true

回執信息,標題是:已讀: 測試回執
References: <16446385.5181199249234389.JavaMail.SYSTEM@svctag-hj8w32x>
Subject: =?gb2312?B?0tG2wTogsuLK1LvY1rQ=?=

從上面看出,你最原始的Message-ID 並沒有返回來,所以不能通過這個判斷
我唯一能想到的,就是這個啦
Subject: =?gb2312?B?suLK1LvY1rQ=?=

回執會把原始的Subject帶回來,所以你應該在Subject裡面加上你的唯一編碼,不要太長就行。

Ⅸ 關於javamail發送郵件的回執

如果是指檢驗郵箱是否存在的話,沒必要去發送郵件,當然如果發送郵件的話也是可以檢驗出來的,如果郵箱不存在的話,發送是失敗的;更簡單一點直接用javaMail中的connect去判定是否存在就可以了:

//根據郵件會話屬性和密碼驗證器構造一個發送郵件的session
SessionsendMailSession=Session
.getDefaultInstance(pro,authenticator);

Transporttransport=sendMailSession.getTransport();

//連接郵件smtp伺服器,參數分別為伺服器地址,用戶名和密碼
transport.connect(serverHost,userName,
mpassword);

如果沒有報錯就返回true,說明郵箱確實存在,否則會拋出MessagingException異常。

Ⅹ javaMail 怎樣判斷收到的郵件是回執郵件

最准確的方法是看信頭 包含Disposition-Notification-To:

最主觀是點擊那封就提示是否回復

閱讀全文

與java郵件回執相關的資料

熱點內容
qq群里的機器人買武器 瀏覽:428
捕魚達人歷史版本 瀏覽:73
mp4視頻文件解密軟體 瀏覽:62
多軸編程哪個軟體最方便 瀏覽:27
老平板哪個是顯示屏數據線插座 瀏覽:849
5sing上傳音頻文件格式 瀏覽:171
win10輸入文件滑鼠右鍵異常 瀏覽:634
聽幼兒故事用什麼app 瀏覽:514
iphone修改音頻文件名 瀏覽:53
國家氣象站點數據在哪裡下載 瀏覽:342
網路設置的網站 瀏覽:914
手機測量放樣怎麼導數據和線型 瀏覽:648
企業展示型網站源碼 瀏覽:781
易花花app哪裡下載 瀏覽:323
外國程序員職業生涯長 瀏覽:709
看理想app怎麼注銷賬號 瀏覽:545
數控銑床加工手工編程的步驟有哪些 瀏覽:411
uc瀏覽器為什麼很多網站進不了 瀏覽:513
西部數據移動硬碟怎麼 瀏覽:645
批處理修改子目錄文件名命令 瀏覽:405

友情鏈接