Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Properties;
- import javax.mail.Address;
- import javax.mail.Message;
- import javax.mail.MessagingException;
- import javax.mail.Multipart;
- import javax.mail.NoSuchProviderException;
- import javax.mail.PasswordAuthentication;
- import javax.mail.Session;
- import javax.mail.Transport;
- import javax.mail.internet.InternetAddress;
- import javax.mail.internet.MimeBodyPart;
- import javax.mail.internet.MimeMessage;
- import javax.mail.internet.MimeMessage.RecipientType;
- import javax.mail.internet.MimeMultipart;
- public class mailTest
- {
- public static void main(String[] args) throws MessagingException
- {
- sendReminder("alix101uk@gmail.com", "DIM3");
- }
- public static void sendReminder(String email, String eventName)
- {
- String host = "smtp.gmail.com";
- String username = "user";
- String password = "passwd";
- Properties props = new Properties();
- props.put("mail.smtps.auth", "true");
- Session session = Session.getDefaultInstance(props,new javax.mail.Authenticator() {
- protected PasswordAuthentication getPasswordAuthentication() {
- return new PasswordAuthentication("psd310f@gmail.com","youhaveproblem");
- }});
- Transport t=null;
- try {
- MimeMessage msg = new MimeMessage(session);
- msg.setRecipient(RecipientType.TO, new InternetAddress(email));
- msg.setSubject("Reminder notification for "+eventName);
- //make a template to pump out here
- msg.setText("Good evening captain!\n\nThis is a reminder for the event:\n\t\t"+eventName+
- "\n\nta much\n\nthe reminder system");
- t = session.getTransport("smtps");
- t.connect(host, username, password);
- t.sendMessage(msg, msg.getAllRecipients());
- t.close();
- }
- catch (MessagingException e)
- {
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement