Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package enviando.email;
- import java.util.Properties;
- import javax.mail.Address;
- import javax.mail.Authenticator;
- import javax.mail.Message;
- import javax.mail.PasswordAuthentication;
- import javax.mail.Session;
- import javax.mail.Transport;
- import javax.mail.internet.InternetAddress;
- import javax.mail.internet.MimeMessage;
- public class App {
- private static String username = "seu-email@gmail.com";
- private static String senha = "sua-senha";
- public static void main(String[] args) {
- try {
- Properties properties = new Properties();
- properties.put("mail.smtp.ssl.trust", "*");
- properties.put("mail.smtp.auth", "true");
- properties.put("mail.smtp.starttls", "true");
- properties.put("mail.smtp.host", "smtp.gmail.com");
- properties.put("mail.smtp.port", "465");
- properties.put("mail.smtp.socketFactory.port", "465");
- properties.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
- properties.put("mail.smtp.ssl.checkserveridentity", "true");
- Session session = Session.getInstance(properties, new Authenticator() {
- @Override
- protected PasswordAuthentication getPasswordAuthentication() {
- return new PasswordAuthentication(username, senha);
- }
- });
- Address[] toUser = InternetAddress.parse("tadeujdev@gmail.com, tadeupalermoti@gmail.com");
- Message message = new MimeMessage(session);
- message.setFrom(new InternetAddress(username, "Tadeu E. Palermo"));
- message.setRecipients(Message.RecipientType.TO, toUser);
- message.setSubject("Chegou e-mail enviado pelo Java!");
- message.setText("Que bom, você recebeu um e-mail enviado pelo Java!");
- Transport.send(message);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement