Created
November 14, 2016 16:41
-
-
Save tassioauad/14490c2dffa4298f3d5ec8efcf0bf3d4 to your computer and use it in GitHub Desktop.
This file contains 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
public class SendEmail { | |
public static void main(String[] args) { | |
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.getDefaultInstance(props, new Authenticator() { | |
protected PasswordAuthentication getPasswordAuthentication() { | |
return new PasswordAuthentication("emailrementente@servidor.com", "senha"); | |
} | |
}); | |
MimeMessage message = new MimeMessage (session); | |
message.setFrom(new InternetAddress("emailrementente@servidor.com")); | |
Address[] toUser = InternetAddress | |
.parse("emaildestinatario@servidor.com"); | |
message.setRecipients(Message.RecipientType.TO, toUser); | |
message.setSubject("Assunto"); | |
message.setText("Texto", "utf-8", "html"); | |
Transport.send(message); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment