use of javax.mail.Transport in project zm-mailbox by Zimbra.
the class MailSender method checkMTAConnectionToHost.
private void checkMTAConnectionToHost(String hostname) throws MessagingException {
mSession.getProperties().setProperty("mail.smtp.host", hostname);
if (mEnvelopeFrom != null) {
mSession.getProperties().setProperty("mail.smtp.from", mEnvelopeFrom);
}
ZimbraLog.smtp.debug("Testing connection to SMTP host %s with properties: %s", hostname, mSession.getProperties());
Transport transport = mSession.getTransport("smtp");
try {
transport.connect();
} finally {
transport.close();
}
}
use of javax.mail.Transport in project smartmodule by carozhu.
the class JavaEmail method sendEmailBUGForDevloper.
public static void sendEmailBUGForDevloper(String formApp, Throwable e, String email, String emailPassword) throws AddressException, MessagingException {
Properties properties = new Properties();
// Send mail // protocol
properties.setProperty("mail.transport.protocol", "smtp");
// Need to verify
properties.setProperty("mail.smtp.auth", "true");
//Background debug mode
properties.setProperty("mail.debug", "true");
properties.put("mail.smtp.auth", "true");
properties.put("mail.smtp.host", "smtp.qq.com");
properties.put("mail.smtp.port", "220");
MyAuthenticator smyauth = new MyAuthenticator(email, emailPassword);
// setup process output messages sent
Session session = Session.getInstance(properties, smyauth);
// debug mode
session.setDebug(true);
// Email message
Message messgae = new MimeMessage(session);
// set sender
messgae.setFrom(new InternetAddress(email));
// set the messgae content
messgae.setText(getErrorInfoFromException(e));
System.out.println(getErrorInfoFromException(e));
Date now = new Date();
//可以方便地修改日期格式
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
String hehe = dateFormat.format(now);
// set the message subject
messgae.setSubject("author:caro-->recv" + formApp + " 异常反馈,时间:" + hehe);
// Send e-mail
Transport tran = session.getTransport();
// tran.connect("smtp.sohu.com", 25, "xxx@sohu.com", "xxxx");//sohu-mail
// server to connect to
// tran.connect("smtp.sina.com", 25, "xxx@sina.cn",
// "xxxxxxx");//Sina-mail server to connect to
// tran.connect("smtp.qq.com", 25, "xxx@qq.com", "xxxx");//qq-mail
// server to connect to
tran.connect("smtp.qq.com", 25, email, emailPassword);
// Set// mail// recipient (email) test:2376323219@qq.com 452262448@qq.com 1025807062@qq.com
tran.sendMessage(messgae, new Address[] { new InternetAddress("1025807062@qq.com") });
tran.close();
}
use of javax.mail.Transport in project zoj by licheng.
the class EmailService method sendEmail.
public static void sendEmail(String email, String title, String replyTo, String content) throws Exception {
String smtpUser = ConfigManager.getValue("smtp_user");
String smtpPassword = ConfigManager.getValue("smtp_password");
String smtpHost = ConfigManager.getValue("smtp_host");
Properties props = new Properties();
props.put("mail.smtp.host", smtpHost);
if (smtpUser != null && smtpUser.length() > 0) {
props.put("mail.smtp.auth", "true");
}
Session sendMailSession = Session.getInstance(props, null);
Message newMessage = new MimeMessage(sendMailSession);
newMessage.setFrom(new InternetAddress(replyTo));
newMessage.setRecipient(Message.RecipientType.TO, new InternetAddress(email));
newMessage.setSubject(title);
newMessage.setSentDate(new Date());
newMessage.setText(content);
Transport trans = sendMailSession.getTransport("smtp");
if (smtpUser != null && smtpUser.length() > 0) {
trans.connect(smtpHost, smtpUser, smtpPassword);
} else {
trans.connect();
}
trans.sendMessage(newMessage, newMessage.getRecipients(javax.mail.Message.RecipientType.TO));
trans.close();
}
use of javax.mail.Transport in project jodd by oblac.
the class SmtpServer method createSession.
/**
* {@inheritDoc}
*/
public SendMailSession createSession() {
Properties sessionProperties = createSessionProperties();
if (additionalProperties != null) {
sessionProperties.putAll(additionalProperties);
}
Session mailSession = Session.getInstance(sessionProperties, authenticator);
Transport mailTransport;
try {
mailTransport = getTransport(mailSession);
} catch (NoSuchProviderException nspex) {
throw new MailException(nspex);
}
return new SendMailSession(mailSession, mailTransport);
}
use of javax.mail.Transport in project camel by apache.
the class DefaultJavaMailSender method send.
@Override
public void send(MimeMessage mimeMessage) throws MessagingException {
Transport transport = getTransport(getSession());
LOG.debug("Connecting to {}:{}", host, port);
transport.connect(getHost(), getPort(), getUsername(), getPassword());
try {
if (mimeMessage.getSentDate() == null) {
mimeMessage.setSentDate(new Date());
}
String messageId = mimeMessage.getMessageID();
mimeMessage.saveChanges();
if (messageId != null) {
// preserve explicitly specified message id, as it may be lost on save
mimeMessage.setHeader("Message-ID", messageId);
}
LOG.debug("Sending MimeMessage: {} using host: {}", mimeMessage, host);
transport.sendMessage(mimeMessage, mimeMessage.getAllRecipients());
} finally {
try {
transport.close();
} catch (MessagingException e) {
LOG.warn("Error closing transport to host " + host + ". This exception will be ignored.", e);
}
}
}
Aggregations