Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package th.in.oneauthen.servlet;
- import java.util.Properties;
- import javax.activation.DataHandler;
- import javax.activation.DataSource;
- import javax.activation.FileDataSource;
- import javax.mail.Message;
- import javax.mail.MessagingException;
- import javax.mail.Multipart;
- import javax.mail.PasswordAuthentication;
- import javax.mail.Session;
- import javax.mail.Transport;
- import javax.mail.internet.InternetAddress;
- import javax.mail.internet.MimeBodyPart;
- import javax.mail.internet.MimeMessage;
- import javax.mail.internet.MimeMultipart;
- public class OneMailServlet {
- public static void SendToOneMail(String locationfile, String email) {
- Properties props = new Properties();
- props.put("mail.smtp.host", "smtp.inetmail.cloud");
- props.put("mail.smtp.socketFactory.port", "25");
- props.put("mail.smtp.socketFactory.class",
- "javax.net.ssl.SSLSocketFactory");
- props.put("mail.smtp.auth", "true");
- props.put("mail.smtp.port", "25");
- Session session = Session.getDefaultInstance(props,
- new javax.mail.Authenticator() {
- protected PasswordAuthentication getPasswordAuthentication() {
- }
- });
- try {
- Message message = new MimeMessage(session);
- message.setRecipients(Message.RecipientType.TO,InternetAddress.parse(email));
- message.setSubject("Signing Document");
- MimeBodyPart messageBodyPart = new MimeBodyPart();
- Multipart multipart = new MimeMultipart();
- messageBodyPart = new MimeBodyPart();
- String file = locationfile;
- String fileName = "Document.pdf";
- DataSource source = new FileDataSource(file);
- messageBodyPart.setDataHandler(new DataHandler(source));
- messageBodyPart.setFileName(fileName);
- multipart.addBodyPart(messageBodyPart);
- message.setContent(multipart);
- System.out.println("Sending");
- Transport.send(message);
- System.out.println("Done");
- } catch (MessagingException e) {
- throw new RuntimeException(e);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment