| Line 17... |
Line 17... |
| 17 |
import javax.mail.internet.AddressException;
|
17 |
import javax.mail.internet.AddressException;
|
| 18 |
import javax.mail.internet.InternetAddress;
|
18 |
import javax.mail.internet.InternetAddress;
|
| 19 |
import javax.mail.internet.MimeBodyPart;
|
19 |
import javax.mail.internet.MimeBodyPart;
|
| 20 |
import javax.mail.internet.MimeMessage;
|
20 |
import javax.mail.internet.MimeMessage;
|
| 21 |
import javax.mail.internet.MimeMultipart;
|
21 |
import javax.mail.internet.MimeMultipart;
|
| - |
|
22 |
import javax.mail.util.ByteArrayDataSource;
|
| 22 |
|
23 |
|
| 23 |
public class GmailUtils {
|
24 |
public class GmailUtils {
|
| 24 |
|
25 |
|
| 25 |
private static final String SMTP_HOST_NAME = "smtp.gmail.com";
|
26 |
private static final String SMTP_HOST_NAME = "smtp.gmail.com";
|
| 26 |
private static final String SMTP_PORT = "465";
|
27 |
private static final String SMTP_PORT = "465";
|
| Line 52... |
Line 53... |
| 52 |
// Put parts in message
|
53 |
// Put parts in message
|
| 53 |
msg.setContent(multipart);
|
54 |
msg.setContent(multipart);
|
| 54 |
Transport.send(msg);
|
55 |
Transport.send(msg);
|
| 55 |
}
|
56 |
}
|
| 56 |
|
57 |
|
| - |
|
58 |
public void sendSSLMessage(String recipients[], String subject, String message, final String from, final String password, String filename, byte[] bytes, String type) throws MessagingException {
|
| - |
|
59 |
Message msg = prepareMessage(recipients, subject, from, password);
|
| - |
|
60 |
|
| - |
|
61 |
//Create the multi-part object to hold the text and attachment parts
|
| - |
|
62 |
Multipart multipart = new MimeMultipart();
|
| - |
|
63 |
|
| - |
|
64 |
// create the message part
|
| - |
|
65 |
MimeBodyPart messageBodyPart = new MimeBodyPart();
|
| - |
|
66 |
//Part 1: Text message
|
| - |
|
67 |
messageBodyPart.setText(message);
|
| - |
|
68 |
multipart.addBodyPart(messageBodyPart);
|
| - |
|
69 |
|
| - |
|
70 |
//Part 2: Attachment
|
| - |
|
71 |
messageBodyPart = new MimeBodyPart();
|
| - |
|
72 |
DataSource source = new ByteArrayDataSource(bytes, type);
|
| - |
|
73 |
messageBodyPart.setDataHandler(new DataHandler(source));
|
| - |
|
74 |
messageBodyPart.setFileName(filename);
|
| - |
|
75 |
multipart.addBodyPart(messageBodyPart);
|
| - |
|
76 |
|
| - |
|
77 |
// Put parts in message
|
| - |
|
78 |
msg.setContent(multipart);
|
| - |
|
79 |
Transport.send(msg);
|
| - |
|
80 |
}
|
| - |
|
81 |
|
| 57 |
public void sendSSLMessage(String recipients[], String subject, String message, final String from, final String password, List<File> files) throws MessagingException {
|
82 |
public void sendSSLMessage(String recipients[], String subject, String message, final String from, final String password, List<File> files) throws MessagingException {
|
| 58 |
Message msg = prepareMessage(recipients, subject, from, password);
|
83 |
Message msg = prepareMessage(recipients, subject, from, password);
|
| 59 |
|
84 |
|
| 60 |
//Create the multi-part object to hold the text and attachment parts
|
85 |
//Create the multi-part object to hold the text and attachment parts
|
| 61 |
Multipart multipart = new MimeMultipart();
|
86 |
Multipart multipart = new MimeMultipart();
|