Created
December 10, 2013 12:37
-
-
Save Sutil/7889946 to your computer and use it in GitHub Desktop.
Envio de e-mail com código JAVA
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private void sendEmail(String destinatario) { | |
| final String username = "user@server.com.br"; | |
| final String password = "password"; | |
| Properties props = new Properties(); | |
| props.put("mail.smtp.auth", "true"); | |
| // props.put("mail.smtp.starttls.enable", "true"); use with gmail | |
| props.put("mail.smtp.host", "mail.csrh.com.br"); | |
| props.put("mail.smtp.port", "587"); | |
| props.put("mail.imap.ssl.checkserveridentity", "false"); // is not necessary with gmail | |
| props.put("mail.imap.ssl.trust", "*"); // is not necessary with gmail | |
| Session session = Session.getInstance(props, new javax.mail.Authenticator() { | |
| protected PasswordAuthentication getPasswordAuthentication() { | |
| return new PasswordAuthentication(username, password); | |
| } | |
| }); | |
| try { | |
| Message message = new MimeMessage(session); | |
| message.setFrom(new InternetAddress("user@server.com.br")); | |
| message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(destinatario)); | |
| message.setSubject("your subject"); | |
| message.setText("Your message"); | |
| Transport.send(message); | |
| } catch (MessagingException e) { | |
| throw new RuntimeException(e); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment