use of javax.mail.Session in project jodd by oblac.
the class Pop3Server method createSession.
/**
* {@inheritDoc}
*/
public ReceiveMailSession createSession() {
Session session = Session.getInstance(sessionProperties, authenticator);
Store store;
try {
store = getStore(session);
} catch (NoSuchProviderException nspex) {
throw new MailException("Failed to create POP3 session", nspex);
}
return new ReceiveMailSession(session, store);
}
use of javax.mail.Session in project spring-boot by spring-projects.
the class MailHealthIndicatorTests method setup.
@Before
public void setup() {
Session session = Session.getDefaultInstance(new Properties());
session.addProvider(new Provider(Type.TRANSPORT, "success", SuccessTransport.class.getName(), "Test", "1.0.0"));
this.mailSender = mock(JavaMailSenderImpl.class);
given(this.mailSender.getHost()).willReturn("smtp.acme.org");
given(this.mailSender.getPort()).willReturn(25);
given(this.mailSender.getSession()).willReturn(session);
this.indicator = new MailHealthIndicator(this.mailSender);
}
use of javax.mail.Session in project google-app-engine-jappstart by taylorleese.
the class MailService method sendActivationEmail.
/**
* Sends the activation e-mail to the given user.
*
* @param user the user
* @param locale the locale
* @throws MessagingException messaging exception
*/
public final void sendActivationEmail(final UserAccount user, final String locale) throws MessagingException {
final Properties props = new Properties();
final Session session = Session.getDefaultInstance(props, null);
final Message message = new MimeMessage(session);
final Multipart multipart = new MimeMultipart();
final MimeBodyPart htmlPart = new MimeBodyPart();
final MimeBodyPart textPart = new MimeBodyPart();
message.setFrom(new InternetAddress(getFromAddress()));
message.addRecipient(Message.RecipientType.TO, new InternetAddress(user.getEmail()));
message.setSubject(messageSource.getMessage("mail.subject", null, new Locale(locale)));
textPart.setContent(messageSource.getMessage("mail.body.txt", new Object[] { getHostname(), user.getActivationKey() }, new Locale(locale)), "text/plain");
htmlPart.setContent(messageSource.getMessage("mail.body.html", new Object[] { getHostname(), user.getActivationKey() }, new Locale(locale)), "text/html");
multipart.addBodyPart(textPart);
multipart.addBodyPart(htmlPart);
message.setContent(multipart);
Transport.send(message);
}
use of javax.mail.Session 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.Session in project nhin-d by DirectProject.
the class DSNGenerator method createDSNMessage.
/**
* Creates a DSN message message.
* @param originalSender The original sender of the message
* @param originalSubject The subject of the original message
* @param postmaster The postmaster address that the DSN message will be from
* @param recipientDSNHeaders A list of recipient DSN headers to populate the delivery status part of the DSN message
* @param messageDSNHeaders The message DSN headers to populate the delivery status part of the DSN message
* @param humanReadableText The human readable part (the first part) or the DSN message
* @return A mime message containing the full DSN message
* @throws MessagingException
*/
public MimeMessage createDSNMessage(InternetAddress originalSender, String originalSubject, InternetAddress postmaster, List<DSNRecipientHeaders> recipientDSNHeaders, DSNMessageHeaders messageDSNHeaders, MimeBodyPart humanReadableText) throws MessagingException {
final DeliveryStatus deliveryStatus = createDeliveryStatus(recipientDSNHeaders, messageDSNHeaders);
// assemble multipart report
final MultipartReport multipartReport = new MultipartReport("", deliveryStatus);
// set name of the delivery status file
multipartReport.getBodyPart(DELIVERY_STATUS_MULTIPART_INDEX).setFileName("status.dat");
// set text body part
multipartReport.setTextBodyPart(humanReadableText);
// create mime message to send from the MultipartReport
final Properties properties = new Properties();
properties.setProperty("mail.from", postmaster.getAddress());
final Session session = Session.getInstance(properties);
final MimeMessage destinationMessage = new MimeMessage(session);
destinationMessage.setSentDate(Calendar.getInstance().getTime());
destinationMessage.setContent(multipartReport);
destinationMessage.setFrom(postmaster);
destinationMessage.addRecipient(RecipientType.TO, originalSender);
destinationMessage.setSubject(subjectPrefix + originalSubject);
destinationMessage.setHeader(MailStandard.Headers.InReplyTo, messageDSNHeaders.getOriginalMessageId());
destinationMessage.saveChanges();
return destinationMessage;
}
Aggregations