java 傳送郵件

2021-08-25 12:57:02 字數 978 閱讀 7600

以下是兩種郵件傳送方式。

給出的例子是是傳送html格式帶附件的郵件。(普通文字格式的郵件基本上可以不關心,現在的郵件都是html格式的!)

如果不要傳送附件,只要傳送單純的html郵件。只要把附件部分去掉即可

/***用spring mail 傳送郵件,依賴jar:spring.jar,activation.jar,mail.jar

*/public static void sendfilemail() throws messagingexception catch (unsupportedencodingexception e)

// 傳送郵件

senderimpl.send(mailmessage);

system.out.println("郵件傳送成功.....");

}

/***用apache commons-email 傳送郵件

*依賴jar:commons-email.jar,activation.jar,mail.jar

*/public static void sendmutimessage() ;

listlist = new arraylist();

for (int j = 0; j < multipaths.length; j++) else catch (malformedurlexception e)

}attachment.setdisposition(emailattachment.attachment);

attachment.setdescription("picture of john");

list.add(attachment);

}try

// 傳送

email.send();

} catch (emailexception e)

}

Java傳送郵件

傳送郵件處理 param longin 郵箱賬號 param password 郵箱授權碼 param sender 郵件傳送者 一般與郵箱賬號相同 param recipient 郵件接收人 param theme 郵件主題 param text 郵件內容 public static void s...

Java 定時傳送郵件

ublic class runmain 附件傳送執行緒 class mail extends thread else else else mail.send system.out.println time 附近已傳送完畢!if this.getid thread.currentthread geti...

java傳送郵件 4

我們的郵箱裡,經常會收到一些非常精美的郵件 註冊使用者名稱發來的郵件,甚至有一些廣告郵件 我們知道這些郵件都是一些html郵件,但是我們知道,要做出這樣乙個精美的html郵件,在程式中,我們得拼多少html和css 啊,豈不是很煩。自從用了spring mail的郵件模板,媽媽再也不用擔心我要拼網頁...