/Users/16484/Desktop/IA_Final_Submission_0003070061/Product/IA_Netbeans_Project/src/ia/prototype/shubha/n/SendMail.java |
1 package ia.prototype.shubha.n;
2
3 import java.util.Properties;
4 import javax.activation.*;
5
6 import javax.mail.*;
7 import javax.mail.internet.*;
8
9
10 public class SendMail {
11
12 public static void send(String msg) {
13
14 final String username = "narayan.ash@gmail.com";
15
16
17 final String password = "xxxx";
18
19 Properties props = new Properties();
20 props.put("mail.smtp.starttls.enable", "true");
21 props.put("mail.smtp.auth", "true");
22 props.put("mail.smtp.host", "smtp.gmail.com");
23 props.put("mail.smtp.port", "587");
24
25 Session session = Session.getInstance(props,
26 new javax.mail.Authenticator() {
27 protected PasswordAuthentication getPasswordAuthentication() {
28 return new PasswordAuthentication(username, password);
29 }
30 });
31
32 try {
33
34 Message message = new MimeMessage(session);
35 message.setFrom(new InternetAddress("narayan.ash@gmail.com"));
36 message.setRecipients(Message.RecipientType.TO,
37 InternetAddress.parse("ashish.narayan@itu.int"));
38 message.setSubject("Testing Subject");
39 message.setText(msg);
40
41 Multipart multipart = new MimeMultipart();
42 message.setContent(multipart);
43
44 Transport.send(message);
45 System.out.println("Mail has been sent");
46
47 } catch (MessagingException e) {
48 e.printStackTrace();
49 throw new RuntimeException(e);
50 }
51 }
52 }