Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.PrintStream;
- import java.util.Properties;
- import javax.mail.Authenticator;
- import javax.mail.Message;
- import javax.mail.Message.RecipientType;
- import javax.mail.MessagingException;
- import javax.mail.PasswordAuthentication;
- import javax.mail.Session;
- import javax.mail.Transport;
- import javax.mail.internet.InternetAddress;
- import javax.mail.internet.MimeMessage;
- public class GoogleMail
- {
- public static void sendEmail(String text, String subject, String recipient)
- {
- String username = "myemail@gmail.com";
- final String password = "gmailpassword";
- Properties props = System.getProperties();
- props.put("mail.smtp.starttls.enable", "true");
- props.put("mail.smtp.host", "smtp.gmail.com");
- props.put("mail.smtp.user", username);
- props.put("mail.smtp.password", password);
- props.put("mail.smtp.port", "587");
- props.put("mail.smtp.auth", "true");
- Session session = Session.getInstance(props, new Authenticator()
- {
- protected PasswordAuthentication getPasswordAuthentication()
- {
- return new PasswordAuthentication(this.val$username, password);
- }
- });
- try
- {
- Message message = new MimeMessage(session);
- message.setFrom(new InternetAddress("myemail@gmail.com"));
- message.setRecipients(Message.RecipientType.TO, InternetAddress.parse("recipient@gmail.com"));
- message.setSubject("Confirmation");
- message.setText("Dear user,\n\nThank you for registering your account with our website. Your encrypted link will be shown below, make sure to click this to register your account, or hook your minecraft account with your website \n\n\nLink:");
- Transport.send(message);
- System.out.println("Done");
- }
- catch (MessagingException e)
- {
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement