-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSendMailBySite.java
More file actions
50 lines (41 loc) · 1.53 KB
/
Copy pathSendMailBySite.java
File metadata and controls
50 lines (41 loc) · 1.53 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
import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.*;
public class SendMailBySite {
public static void main(String[] args) {
String host="mail.fmsolutions.tech";
final String user="customerservice@fmsolutions.tech";//change accordingly
final String password="7dRR5bmKoCQH";//change accordingly
String to="cheeran@hotmail.com";//change accordingly
//Get the session object
Properties props = new Properties();
props.put("mail.smtp.host",host);
props.put("mail.smtp.auth", "true");
// enable authentication
props.put("mail.smtp.auth", "true");
// SSL Port
props.put("mail.smtp.port", "465");
// SSL Factory
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
System.out.println("Sending email ...");
Session session = Session.getDefaultInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(user,password);
}
});
//Compose the message
try {
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(user));
message.addRecipient(Message.RecipientType.TO,new InternetAddress(to));
message.setSubject("javatpoint");
message.setText("This is simple program of sending email using JavaMail API");
//send the message
Transport.send(message);
System.out.println("Email Sent Successfully...");
} catch (MessagingException e) {
e.printStackTrace();
}
}
}