-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGoogleMail.java
More file actions
61 lines (51 loc) · 1.58 KB
/
Copy pathGoogleMail.java
File metadata and controls
61 lines (51 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package rwb.java.mail;
import java.util.Properties;
import javax.mail.Message;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import rwb.java.divers.Log;
public class GoogleMail {
/**
* Class constructor
*/
public GoogleMail(){
//nothing to do
}
/**
*
* @param mailFrom
* @param mdp
* @param mailTo
* @param textMessage
* @return
*/
public boolean sendMail(String mailFrom, String mdp, String mailTo, String textMessage) {
Properties props = new Properties();
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.port", "587");
Session session = Session.getInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(mailFrom, mdp);
}
});
try {
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(mailFrom));
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse(mailTo));
message.setSubject("Remote Web Box");
message.setText(textMessage);
Transport.send(message);
return true;
} catch (Exception e) {
Log.warning(e.toString());
return false;
}
}
}