Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package pl.codeme.hackathon.GrzmotoPtak;
- import java.util.Properties;
- import java.util.Scanner;
- import javax.mail.*;
- import javax.mail.internet.AddressException;
- import javax.mail.internet.InternetAddress;
- import javax.mail.internet.MimeMessage;
- import pl.codeme.hackathon.GrzmotoPtak.*;
- public class App extends Config
- {
- public static void main( String[] args )
- {
- final String username = "hackathon123456@gmail.com";
- final String password = "hack1234";
- Session session = Session.getInstance(gmailProperties(),
- new javax.mail.Authenticator() {
- protected PasswordAuthentication getPasswordAuthentication() {
- return new PasswordAuthentication(username, password);
- }
- });
- try {
- MimeMessage message = new MimeMessage(session);
- Address addressfrom = new InternetAddress("hackathon123456@gmail.com");
- Address addressto = new InternetAddress("adamkartanowicz@gmail.com");
- message.setFrom(addressfrom);
- message.setRecipient(Message.RecipientType.TO, addressto);
- message.setSubject("Test");
- message.setText("Testowa wiadomosc");
- Transport.send(message);
- } catch (AddressException e) {} catch (MessagingException e) {}
- System.out.println("Zrobione!");
- }
- public static Properties gmailProperties () {
- Properties props = new Properties();
- props.put("mail.smtp.auth", "true");
- props.put("mail.smtp.starttls.enable", "true");
- props.put("mail.smtp.host", "smtp.gmail.com");
- props.put("mail.smtp.port", "587");
- return props;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement