01.
public
static
void
main(String[] args) {
02.
03.
final
String auth_host =
"mail.thaicreate.com"
;
04.
final
String auth_port =
"25"
;
05.
final
String auth_email =
"no-reply@thaicreate.com"
;
06.
final
String auth_password =
"password"
;
07.
08.
Properties props =
new
Properties();
09.
props.put(
"mail.smtp.host"
, auth_host);
10.
props.put(
"mail.smtp.socketFactory.port"
, auth_port);
11.
props.put(
"mail.smtp.socketFactory.class"
,
12.
"javax.net.ssl.SSLSocketFactory"
);
13.
props.put(
"mail.smtp.auth"
,
"true"
);
14.
props.put(
"mail.smtp.port"
, auth_port);
15.
16.
17.
try
{
18.
19.
Session mailSession = Session.getInstance(props,
20.
new
javax.mail.Authenticator() {
21.
protected
PasswordAuthentication
22.
getPasswordAuthentication() {
23.
return
new
PasswordAuthentication
24.
(auth_email,auth_password);
25.
}
26.
});
27.
28.
Message message =
new
MimeMessage(mailSession);
29.
30.
message.setFrom(
new
InternetAddress(auth_email));
31.
32.
33.
message.setRecipients(Message.RecipientType.TO,
34.
InternetAddress.parse(
"thacreate@hotmail.com"
));
35.
message.setSubject(
"Test sending mail from Java"
);
36.
message.setText(
"Hello mr.win, Please do not reply this mail"
);
37.
38.
Transport.send(message);
39.
40.
System.out.println(
"Mail Send Successfully."
);
41.
42.
}
catch
(MessagingException e) {
43.
throw
new
RuntimeException(e);
44.
}
45.
46.
}