use of javax.mail.Authenticator in project suite by stupidsing.
the class SmtpSslGmail method send.
public void send(String to, String subject, String body) {
Constants.bindSecrets("gmail .0 .1").map((username, enc) -> {
String password = decode(System.getenv("USER").toCharArray(), enc);
Properties props = new Properties();
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.port", "465");
props.put("mail.smtp.socketFactory.port", "465");
props.put("mail.smtp.socketFactory.class", SSLSocketFactory.class.getName());
Session session = Session.getDefaultInstance(props, new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
try {
String sender = username + "@gmail.com";
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(sender));
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to != null ? to : sender));
message.setSubject(subject);
message.setText(body);
Transport.send(message);
} catch (MessagingException e) {
Fail.t(e);
}
return true;
});
}
use of javax.mail.Authenticator in project apex-malhar by apache.
the class SmtpOutputOperator method reset.
private void reset() {
if (!setupCalled) {
return;
}
if (!StringUtils.isBlank(smtpPassword)) {
properties.setProperty("mail.smtp.auth", "true");
properties.setProperty("mail.smtp.starttls.enable", "true");
if (useSsl) {
properties.setProperty("mail.smtp.socketFactory.port", String.valueOf(smtpPort));
properties.setProperty("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
properties.setProperty("mail.smtp.socketFactory.fallback", "false");
}
auth = new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(smtpUserName, smtpPassword);
}
};
}
properties.setProperty("mail.smtp.host", smtpHost);
properties.setProperty("mail.smtp.port", String.valueOf(smtpPort));
session = Session.getInstance(properties, auth);
resetMessage();
}
use of javax.mail.Authenticator in project tomee by apache.
the class EmailService method lowerCase.
@POST
public String lowerCase(final String message) {
try {
// Create some properties and get the default Session
final Properties props = new Properties();
props.put("mail.smtp.host", "your.mailserver.host");
props.put("mail.debug", "true");
final Session session = Session.getInstance(props, new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("MyUsername", "MyPassword");
}
});
// Set this just to see some internal logging
session.setDebug(true);
// Create a message
final MimeMessage msg = new MimeMessage(session);
msg.setFrom(new InternetAddress("your@email.address"));
final InternetAddress[] address = { new InternetAddress("user@provider.com") };
msg.setRecipients(Message.RecipientType.TO, address);
msg.setSubject("JavaMail API test");
msg.setSentDate(new Date());
msg.setText(message, "UTF-8");
Transport.send(msg);
} catch (final MessagingException e) {
return "Failed to send message: " + e.getMessage();
}
return "Sent";
}
use of javax.mail.Authenticator in project gocd by gocd.
the class Pop3MailClient method getInboxFolder.
private Folder getInboxFolder() throws MessagingException {
Properties pop3Props = new Properties();
pop3Props.setProperty("mail.pop3.host", host);
Authenticator auth = new PopupAuthenticator();
Session session = Session.getInstance(pop3Props, auth);
URLName url = new URLName("pop3", host, port, "", username, password);
Store store = session.getStore(url);
store.connect();
Folder folder = store.getFolder("INBOX");
folder.open(Folder.READ_WRITE);
return folder;
}
use of javax.mail.Authenticator in project tomee by apache.
the class MailSessionFactory method create.
public Session create() {
final String password = properties.getProperty("password");
Authenticator auth = null;
if (password != null) {
final String protocol = properties.getProperty("mail.transport.protocol", "smtp");
String user = properties.getProperty("mail." + protocol + ".user");
if (user == null) {
user = properties.getProperty("mail.user");
}
if (user != null) {
final PasswordAuthentication pa = new PasswordAuthentication(user, password);
auth = new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return pa;
}
};
}
}
if (useDefault) {
if (auth != null) {
return Session.getDefaultInstance(properties, auth);
}
return Session.getDefaultInstance(properties);
}
if (auth != null) {
return Session.getInstance(properties, auth);
}
return Session.getInstance(properties);
}
Aggregations