use of org.springframework.mail.javamail.JavaMailSenderImpl in project ngtesting-platform by aaronchen2k.
the class SystemConfig method javaMailSender.
@Bean
public JavaMailSender javaMailSender() {
JavaMailSenderImpl javaMailSender = new JavaMailSenderImpl();
javaMailSender.setHost(mailHost);
javaMailSender.setPort(mailPort);
javaMailSender.setUsername(mailUserName);
javaMailSender.setPassword(mailPassword);
Properties p = new Properties();
p.setProperty("mail.smtp.auth", "true");
p.setProperty("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
javaMailSender.setJavaMailProperties(p);
return javaMailSender;
}
use of org.springframework.mail.javamail.JavaMailSenderImpl in project flytecnologia-api by jullierme.
the class FlyMailConfig method mailSender.
@Bean
public JavaMailSender mailSender() {
JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
mailSender.setHost(env.getProperty("spring.mail.host"));
mailSender.setPort(env.getProperty("spring.mail.port", Integer.class));
mailSender.setUsername(env.getProperty("spring.mail.username"));
mailSender.setPassword(env.getProperty("spring.mail.password"));
mailSender.setProtocol(env.getProperty("spring.mail.protocol"));
Properties props = mailSender.getJavaMailProperties();
props.put("mail.smtp.auth", true);
props.put("mail.smtp.starttls.enable", true);
props.put("mail.smtp.connectiontimeout", 10000);
props.put("mail.default-encoding", "UTF-8");
return mailSender;
}
use of org.springframework.mail.javamail.JavaMailSenderImpl in project spring-integration-samples by spring-projects.
the class MimeMessageParsingTest method testProcessingOfNestedEmailAttachments.
/**
* This test will create a Mime Message that in return contains another
* mime message. The nested mime message contains an attachment.
*
* The root message consist of both HTML and Text message.
*/
@Test
public void testProcessingOfNestedEmailAttachments() {
final JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
mailSender.setPort(this.wiserPort);
final MimeMessage rootMessage = mailSender.createMimeMessage();
try {
final MimeMessageHelper messageHelper = new MimeMessageHelper(rootMessage, true);
messageHelper.setFrom("testfrom@springintegration.org");
messageHelper.setTo("testto@springintegration.org");
messageHelper.setSubject("Parsing of Attachments");
messageHelper.setText("Spring Integration Rocks!", "Spring Integration <b>Rocks</b>!");
final String pictureName = "picture.png";
final ByteArrayResource byteArrayResource = getFileData(pictureName);
messageHelper.addInline("picture12345", byteArrayResource, "image/png");
} catch (MessagingException e) {
throw new MailParseException(e);
}
mailSender.send(rootMessage);
final List<WiserMessage> wiserMessages = wiser.getMessages();
Assert.assertTrue(wiserMessages.size() == 1);
boolean foundTextMessage = false;
boolean foundPicture = false;
boolean foundHtmlMessage = false;
for (WiserMessage wiserMessage : wiserMessages) {
List<EmailFragment> emailFragments = new ArrayList<EmailFragment>();
try {
final MimeMessage mailMessage = wiserMessage.getMimeMessage();
EmailParserUtils.handleMessage(null, mailMessage, emailFragments);
} catch (MessagingException e) {
throw new IllegalStateException("Error while retrieving Mime Message.");
}
Assert.assertTrue(emailFragments.size() == 3);
for (EmailFragment emailFragment : emailFragments) {
if ("<picture12345>".equals(emailFragment.getFilename())) {
foundPicture = true;
}
if ("message.txt".equals(emailFragment.getFilename())) {
foundTextMessage = true;
}
if ("message.html".equals(emailFragment.getFilename())) {
foundHtmlMessage = true;
}
}
Assert.assertTrue(foundPicture);
Assert.assertTrue(foundTextMessage);
Assert.assertTrue(foundHtmlMessage);
}
}
use of org.springframework.mail.javamail.JavaMailSenderImpl in project neubbs by nuitcoder.
the class SendEmailUtil method send.
/**
* 发送(邮件)
* - 构建邮件请求
* - 构建参数
* - 构建连接
* - 构建消息
* - 设置发件人 + 昵称
* - 设置主题 + 内容
* - 设置收件人
* - 保存更改
* - 发送邮件
*
* @param sendNickname 发件人昵称
* @param receiveEmail 接收邮箱
* @param sendSubject 发送主题
* @param sendEmailContent 发送内容
*/
public static void send(String sendNickname, String receiveEmail, String sendSubject, String sendEmailContent) {
JavaMailSenderImpl sender = new JavaMailSenderImpl();
sender.setUsername(FROM_USERNAME);
sender.setPassword(FROM_AUTHORIZATION_CODE);
sender.setHost(SetConst.TO_HOST);
sender.setProtocol(SetConst.TO_SMTP);
sender.setPort(Integer.parseInt(SetConst.TO_SMTP_SSL_PROT));
Properties properties = new Properties();
properties.setProperty(SetConst.TO_AUTH, SetConst.TO_AUTH_TRUE);
properties.setProperty(SetConst.TO_MAIL_SMTP_SOCKETFACTORY_CLASS, SetConst.TO_JAVAX_NET_SSL_SSLSOCKETFACTORY);
properties.setProperty(SetConst.TO_MAIL_SMTP_SOCKETFACTORY_PORT, SetConst.TO_SMTP_SSL_PROT);
sender.setJavaMailProperties(properties);
Session mailSession = Session.getDefaultInstance(properties, new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(FROM_USERNAME, FROM_AUTHORIZATION_CODE);
}
});
MimeMessage message = new MimeMessage(mailSession);
try {
message.setFrom(new InternetAddress(FROM_USERNAME, sendNickname));
message.setSubject(sendSubject, SetConst.FROM_SUBJECT_ENCODING);
message.setContent(sendEmailContent, SetConst.FROM_CONTENT_TYPE);
message.addRecipient(Message.RecipientType.TO, new InternetAddress(receiveEmail));
message.saveChanges();
} catch (UnsupportedEncodingException | MessagingException uee) {
uee.printStackTrace();
}
sender.send(message);
}
use of org.springframework.mail.javamail.JavaMailSenderImpl in project thingsboard by thingsboard.
the class MailPlugin method initMailSender.
private void initMailSender(MailPluginConfiguration configuration) {
JavaMailSenderImpl mail = new JavaMailSenderImpl();
mail.setHost(configuration.getHost());
mail.setPort(configuration.getPort());
mail.setUsername(configuration.getUsername());
mail.setPassword(configuration.getPassword());
if (configuration.getOtherProperties() != null) {
Properties mailProperties = new Properties();
configuration.getOtherProperties().forEach(p -> mailProperties.put(p.getKey(), p.getValue()));
mail.setJavaMailProperties(mailProperties);
}
mailSender = mail;
}
Aggregations