this.password = password; Properties props = new Properties(); props.setProperty("mail.transport.protocol", "smtp"); props.setProperty("mail.host", mailhost); props.put("mail.smtp.auth", "true"); props.put("mail.smtp.port", "465"); props.put("mail.smtp.socketFactory.port", "465"); props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory"); return new PasswordAuthentication(user, password); MimeMessage message = new MimeMessage(session); DataHandler handler = new DataHandler(new ByteArrayDataSource(body.getBytes(), "text/plain")); message.setSender(new InternetAddress(sender)); message.setSubject(subject); message.setDataHandler(handler); message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(recipients)); else message.setRecipient(Message.RecipientType.TO, new InternetAddress(recipients)); Transport.send(message); }catch(Exception e){
private Session createSmtpSession() { final Properties props = new Properties(); props.setProperty("mail.smtp.host", "smtp.gmail.com"); props.setProperty("mail.smtp.auth", "true"); props.setProperty("mail.smtp.port", "" + 587); props.setProperty("mail.smtp.starttls.enable", "true"); // props.setProperty("mail.debug", "true"); return Session.getDefaultInstance(props, new javax.mail.Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication("john.doe@gmail.com", "mypassword"); } }); }
private static Properties props; private static Session session; static { props = new Properties(); props.put("mail.smtp.starttls.enable", "true"); props.put("mail.smtp.port", "587"); props.put("mail.smtp.host", "m.outlook.com"); props.put("mail.smtp.auth", "true"); session = Session.getInstance(props, new Authenticator() { @Override protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication("office365 email address" "office365 password"); } }); }
protected PasswordAuthentication getPasswordAuthentication() { String requestingHost = getRequestingHost(); if (requestingHost == proxyHost){ System.out.println("getPasswordAuthentication() request recieved from->" + requestingHost ); return new PasswordAuthentication(proxyuser,proxypass.toCharArray()); } else{ System.out.println("getPasswordAuthentication() request recieved from->" + requestingHost ); return new PasswordAuthentication(sharepointusername,sharepointpassword.toCharArray()); } }
String to = "abcd@gmail.com"; String from = "web@gmail.com"; Properties properties = System.getProperties(); properties.setProperty("mail.smtp.host", SMPT_HOSTNAME); Session session = Session.getInstance(properties, new Authenticator() { @Override protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(USERNAME, PASSWORD); } }); try { MimeMessage message = new MimeMessage(session); message.setFrom(new InternetAddress(from)); message.addRecipient(Message.RecipientType.TO, new InternetAddress( to)); message.setSubject("This is the Subject Line!"); message.setText("This is actual message"); Transport.send(message); System.out.println("Sent message successfully...."); } catch (MessagingException mex) { mex.printStackTrace(); }
/** * Specifies a username and password for on-demand authentication. Will only send * the authorization header when challenged for the specified realm. * @param realm the realm for which the credentials apply. * @param username the user to authenticate * @param password the credentials for the user */ public void setAuthentication( String realm, String username, String password ) { _credentials.put( realm, new PasswordAuthentication( username, password.toCharArray() ) ); }
Properties mailProps = new Properties(); mailProps.put("mail.smtp.from", from); mailProps.put("mail.smtp.host", smtpHost); mailProps.put("mail.smtp.port", port); mailProps.put("mail.smtp.auth", true); mailProps.put("mail.smtp.socketFactory.port", port); return new PasswordAuthentication(login, password); InternetAddress dests[] = new InternetAddress[emails.length]; for (int i = 0; i < emails.length; i++) { dests[i] = new InternetAddress(emails[i].trim().toLowerCase());
emailPorperties = new Properties(); emailPorperties.put("mail.smtp.host", "your host"); emailPorperties.put("mail.smtp.socketFactory.port", "your port"); emailPorperties.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory"); emailPorperties.put("mail.smtp.auth", "true"); emailPorperties.put("mail.smtp.port", "your port"); emailPorperties.put("mail.smtp.ssl.enable", "true"); emailSession = Session.getInstance(emailPorperties, new Authenticator() { @Override protected PasswordAuthentication getPasswordAuthentication() { System.out.println("Authenticating"); return new PasswordAuthentication(USER_NAME, PASSWORD); } });
Properties props = null; try { props = new Properties(System.getProperties()); } catch (SecurityException ex) { props = new Properties(); props.put("mail.smtp.host", getSMTPHost()); props.put("mail.smtp.starttls.enable", "true"); props.put("mail.smtp.auth", "true"); auth = new Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(getSMTPUsername(), getSMTPPassword());
public void readMails() { properties = new Properties(); properties.setProperty("mail.host", "mail.etranssolutions.com"); //properties.setProperty("mail.port", "110"); properties.setProperty("mail.transport.protocol", "imap"); session = Session.getInstance(properties, new javax.mail.Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(userName, password); } }); try { store = session.getStore("imap"); ...... (Rest Of the Code As it is ... )
/** * Specifies a username and password for on-demand authentication. Will only send * the authorization header when challenged for the specified realm. * @param realm the realm for which the credentials apply. * @param username the user to authenticate * @param password the credentials for the user */ public void setAuthentication( String realm, String username, String password ) { _credentials.put( realm, new PasswordAuthentication( username, password.toCharArray() ) ); }
final String password = "yourpassword"; Properties props = new Properties(); props.put("mail.smtp.starttls.enable", "true"); props.put("mail.smtp.auth", "true"); props.put("mail.smtp.host", "smtp.gmail.com"); props.put("mail.smtp.port", "587"); new javax.mail.Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(username, password); message.setFrom(new InternetAddress("your_user_name@gmail.com")); message.setRecipients(Message.RecipientType.TO, InternetAddress.parse("to_email_address@domain.com")); System.out.println("Done");
URL url = new URL("YOUR URL HERE"); Authenticator.setDefault(new Authenticator(){ @Override protected PasswordAuthentication getPasswordAuthentication() { System.err.println("Feeding username and password for " + getRequestingScheme()); return (new PasswordAuthentication("username", "password".toCharArray())); }}); InputStream stream = url.openStream();
final Properties props = new Properties(); props.put("mail.smtp.host", config.getSmtpHost()); props.setProperty("mail.smtp.auth", "true"); Session session = Session.getDefaultInstance(props, new javax.mail.Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(config.getSmtpUser(), config.getSmtpPassword()); } });
Properties props = new Properties(); props.setProperty("mail.transport.protocol", "smtp"); props.setProperty("mail.smtp.host", "out.alice.it"); props.setProperty("mail.smtp.auth", "true"); final PasswordAuthentication auth = new PasswordAuthentication(smtpUser, stmpPassword); Session mailSession = Session.getDefaultInstance(props, new Authenticator() { @Override protected PasswordAuthentication getPasswordAuthentication() { return auth; } }); MimeMessage message = ....; // compose the message Transport.send(message);
/** * Specifies a username and password for on-demand authentication. Will only send * the authorization header when challenged for the specified realm. * @param realm the realm for which the credentials apply. * @param username the user to authenticate * @param password the credentials for the user */ public void setAuthentication( String realm, String username, String password ) { _credentials.put( realm, new PasswordAuthentication( username, password.toCharArray() ) ); }
final String password = "your.password"; 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"); new javax.mail.Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(username, password); message.setFrom(new InternetAddress("from.mail.id@gmail.com")); message.setRecipients(Message.RecipientType.TO, InternetAddress.parse("to.mail.id@gmail.com")); System.out.println("Sending"); System.out.println("Done");
static class MyAuthenticator extends Authenticator { public PasswordAuthentication getPasswordAuthentication() { // I haven't checked getRequestingScheme() here, since for NTLM // and Negotiate, the usrname and password are all the same. System.err.println("Feeding username and password for " + getRequestingScheme()); return (new PasswordAuthentication(kuser, kpass.toCharArray())); } }
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"); Session session = Session.getInstance(props, new javax.mail.Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(username, password); } });
Properties props = System.getProperties(); props.setProperty("mail.store.protocol", "imaps"); props.put("mail.smtp.starttls.enable","true"); Authenticator auth = new Authenticator() { protected PasswordAuthentication getPasswordAuthentication(){ return new PasswordAuthentication("USEREMAILID","PASSWORD "); } }; sessioned= Session.getDefaultInstance(props, auth); store = sessioned.getStore("imaps"); store.connect("smtp.gmail.com","USEREMAILID","PASSWORD ");