-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestForMailFromLarka.java.txt
More file actions
56 lines (43 loc) · 1.71 KB
/
testForMailFromLarka.java.txt
File metadata and controls
56 lines (43 loc) · 1.71 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
package test;
import java.io.UnsupportedEncodingException;
import java.util.Properties;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
public class SendMail {
public static void main(String[] args) {
final String username = ""; //email
final String password = "";
String host = "smtp.gmail.com";
Properties pro = new Properties();
pro.put("mail.smtp.host",host);
pro.put("mail.smtp.socketFactory.port","465");
pro.put("mail.smtp.socketFactory.class","javax.net.ssl.SSLSocketFactory");
pro.put("mail.smtp.auth","true");
pro.put("mail.smtp.port","465");
Session session = Session.getInstance(pro,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
try {
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress("swbashir404@gmail"));
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse("sulemanbashir02@gmail.com"));
message.setSubject("Testing Larkay");
message.setText("Dear Larkay,"
+ "\n\n No spam to my email, please!");
Transport.send(message);
System.out.println("Done");
} catch (MessagingException e) {
throw new RuntimeException(e);
}
}
}