-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNmail.java
68 lines (60 loc) · 2.75 KB
/
Nmail.java
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
62
63
64
65
66
67
68
package ita;
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.InternetAddress;
import javax.mail.internet.MimeMessage;
public class Nmail {
public void sendotp(String a,int rand){
String to = a;
String from = "[email protected]";
Properties pro=new Properties();
pro.put("mail.smtp.auth","true");
pro.put("mail.smtp.starttls.enable", "true");
pro.put("mail.smtp.host", "smtp.gmail.com");
pro.put("mail.smtp.port", 587);
Session session = Session.getDefaultInstance(pro,new javax.mail.Authenticator()
{
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("[email protected]","indian@india");
}
});
try {
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
message.setSubject("This is OTP from \" INDIAN Editor \" to verify your GMail Account");
message.setText(rand+" This is OTP for login in javaprojects "+"\n"+"don't share this otp to other ."
+ "\n If you not login leave it...");
Transport.send(message);
System.out.println("Sent message successfully....");
}catch (MessagingException mex) {mex.printStackTrace();}
}
public void sendsucs(String a){
String to = a;
String from = "[email protected]";
Properties pro=new Properties();
pro.put("mail.smtp.auth","true");
pro.put("mail.smtp.starttls.enable", "true");
pro.put("mail.smtp.host", "smtp.gmail.com");
pro.put("mail.smtp.port", 587);
Session session = Session.getDefaultInstance(pro,new javax.mail.Authenticator()
{
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("[email protected]","indian@india");
}
});
try {
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
message.setSubject(" \" INDIAN Editor \" sucessfully verify your GMail Account");
message.setText(" Your MailID is sucessfully verified!!");
Transport.send(message);
System.out.println("Sent message successfully....");
}catch (MessagingException mex) {mex.printStackTrace();}
}
}