Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void sendGmail(String dest, String subject, String msgText) {
- final String username = "adresse@gmail.com";
- final String password = "password";
- Properties props = new Properties();
- props.put("mail.smtp.host", "smtp.gmail.com");
- props.put("mail.smtp.socketFactory.port", "465");
- props.put("mail.smtp.socketFactory.class",
- "javax.net.ssl.SSLSocketFactory");
- props.put("mail.smtp.auth", "true");
- props.put("mail.smtp.port", "465");
- Session session = Session.getInstance(props,
- new javax.mail.Authenticator() {
- protected PasswordAuthentication getPasswordAuthentication() {
- return new PasswordAuthentication(username, password);
- }
- });
- try {
- Message message = new MimeMessage(session);
- message.setHeader("Content-Type", "text/html; charset=UTF-8");
- message.setFrom(new InternetAddress("Hotel Ocean Beach" + " <" + username + ">"));
- message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(dest));
- message.setSubject(subject);
- message.setContent(msgText, "text/html; charset=UTF-8");
- Transport.send(message);
- } catch (MessagingException e) {
- throw new RuntimeException(e);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement