提交 | 用户 | 时间
|
58d006
|
1 |
package com.mandi.common.mail; |
A |
2 |
|
|
3 |
import java.util.Properties; |
|
4 |
|
|
5 |
import javax.mail.Authenticator; |
|
6 |
import javax.mail.Message; |
|
7 |
import javax.mail.Message.RecipientType; |
|
8 |
import javax.mail.MessagingException; |
|
9 |
import javax.mail.PasswordAuthentication; |
|
10 |
import javax.mail.Session; |
|
11 |
import javax.mail.Transport; |
|
12 |
import javax.mail.internet.AddressException; |
|
13 |
import javax.mail.internet.InternetAddress; |
|
14 |
import javax.mail.internet.MimeMessage; |
|
15 |
|
|
16 |
|
|
17 |
public class Mailmethod { |
|
18 |
public static boolean mailsend(String dest,String title,String content) |
|
19 |
{ |
|
20 |
if(dest==null) |
|
21 |
return false; |
|
22 |
Properties ps=new Properties(); |
|
23 |
ps.setProperty("mail.transport.protocol", "smtp"); |
|
24 |
ps.setProperty("mail.smtp.auth", "true"); |
|
25 |
ps.setProperty("mail.smtp.host", "smtp.126.com"); |
|
26 |
Session s=Session.getInstance(ps,new Ma()); |
|
27 |
s.setDebug(false); |
|
28 |
Message m=new MimeMessage(s); |
|
29 |
//如果复杂内哟,要用Mimebodypart |
|
30 |
/*MimeBodyPart bodyPartAttch = createAttachMent("C:\\Users\\Administrator\\Desktop\\mail.jar");//附件 |
|
31 |
MimeBodyPart bodyPartContentAndPic = createContentAndPic("I just want to Fuck","C:\\Users\\Administrator\\Desktop\\0.jpg");//文本内容 |
|
32 |
MimeMultipart mimeMuti = new MimeMultipart("mixed"); |
|
33 |
mimeMuti.addBodyPart(bodyPartAttch); |
|
34 |
mimeMuti.addBodyPart(bodyPartContentAndPic); |
|
35 |
message.setContent(mimeMuti); |
|
36 |
message.saveChanges(); |
|
37 |
* */ |
|
38 |
try { |
|
39 |
m.setFrom(new InternetAddress(Ma.userName)); |
|
40 |
m.setSubject(title); |
|
41 |
String[] dests=dest.split(";"); |
|
42 |
for (String string : dests) { |
|
43 |
m.setRecipients(RecipientType.TO, InternetAddress.parse(string)); |
|
44 |
} |
|
45 |
m.setText(content); |
|
46 |
Transport.send(m); |
|
47 |
} catch (AddressException e) { |
|
48 |
e.printStackTrace(); |
|
49 |
} catch (MessagingException e) { |
|
50 |
e.printStackTrace(); |
|
51 |
} |
|
52 |
|
|
53 |
return true; |
|
54 |
} |
|
55 |
|
|
56 |
} |