Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void sendmail(){
- System.out.println("started function");
- String from = "amritharajeevan.77@gmail.com";
- // Sender's email ID needs to be mentioned
- String to = "amritha2.rajeevan@aricent.com";
- final String username = "amritharajeevan.77";//change accordingly
- final String password = "vivekrajeevan";//change accordingly
- // Assuming you are sending email through gmail.com
- String host = "smtp.gmail.com";
- Properties props = new Properties();
- props.put("mail.smtp.auth", "true");
- props.put("mail.smtp.starttls.enable", "true");
- props.put("mail.smtp.host", host);
- props.put("mail.smtp.port", "25");
- Session session = Session.getInstance(props,
- new javax.mail.Authenticator() {
- protected javax.mail.PasswordAuthentication getPasswordAuthentication() {
- return new javax.mail.PasswordAuthentication(username, password);
- }
- });
- try {
- Message message = new MimeMessage(session);
- message.setFrom(new InternetAddress(from));
- message.setRecipients(Message.RecipientType.TO,
- InternetAddress.parse(to));
- message.setSubject("Server Error");
- BodyPart messageBodyPart = new MimeBodyPart();
- messageBodyPart.setText("Server"+" " +servererror+ " " +" is unreachable. Please check the logs.");
- Multipart multipart = new MimeMultipart();
- multipart.addBodyPart(messageBodyPart);
- messageBodyPart = new MimeBodyPart();
- String filename = "/Users/aricent/Desktop/amritha/seetest/May6.zip";
- DataSource source = new FileDataSource(filename);
- messageBodyPart.setDataHandler(new DataHandler(source));
- messageBodyPart.setFileName(filename);
- multipart.addBodyPart(messageBodyPart);
- message.setContent(multipart);
- System.out.println("sent start function");
- Transport.send(message);
- System.out.println("Sent message successfully....");
- } catch (MessagingException e) {
- throw new RuntimeException(e);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement