本文整理汇总了Java中javax.mail.Transport.close方法的典型用法代码示例。如果您正苦于以下问题:Java Transport.close方法的具体用法?Java Transport.close怎么用?Java Transport.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.mail.Transport
的用法示例。
在下文中一共展示了Transport.close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: iMessage
import javax.mail.Transport; //导入方法依赖的package包/类
public static boolean iMessage() {
try {
message.setContent(mp);
message.saveChanges();
Session mailSession = Session.getInstance(props, null);
Transport transport = mailSession.getTransport("smtp");
transport.connect((String) props.get("mail.smtp.host"),
(Integer) props.get("mail.smtp.port"), username, password);
transport.sendMessage(message,
message.getRecipients(javax.mail.Message.RecipientType.TO));
transport.close();
} catch (MessagingException e) {
return false;
}
return true;
}
示例2: sendCodeMail
import javax.mail.Transport; //导入方法依赖的package包/类
/**
* 发送邮件,从公邮里发邮件给成员变量email。
*
* @throws Exception 可能会有异常抛出,建议打出Log。
*/
public void sendCodeMail() throws MessagingException, UnsupportedEncodingException {
if (email == null) {
Log.e("sendCodeMail","调用错误");
return;
}
//创建一封邮件
MimeMessage message = createCodeMessage(session, myEmailAccount, email);
Transport transport = session.getTransport();
//使用 邮箱账号 和 密码 连接邮件服务器, 这里认证的邮箱必须与 message 中的发件人邮箱一致, 否则报错
transport.connect(myEmailAccount, myEmailPassword);
transport.sendMessage(message, message.getAllRecipients());
transport.close();
}
示例3: sendMail
import javax.mail.Transport; //导入方法依赖的package包/类
private static void sendMail()
throws MessagingException, IOException {
Session session = Session.getInstance(getMailProps(), new javax.mail.Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(
getVal("username"),
getVal("password"));
}
});
session.setDebug(getBoolVal("mail.debug"));
LOG.info("Compiling Mail before Sending");
Message message = createMessage(session);
Transport transport = session.getTransport("smtp");
LOG.info("Connecting to Mail Server");
transport.connect();
LOG.info("Sending Mail");
transport.sendMessage(message, message.getAllRecipients());
transport.close();
LOG.info("Reports are sent to Mail");
clearTempZips();
}
示例4: authentication
import javax.mail.Transport; //导入方法依赖的package包/类
/**
* authentication
*/
public static Boolean authentication(EmailSettingContent emailSetting) {
Properties props = buildProperty(emailSetting);
Session session = Session.getInstance(props, null);
try {
Transport transport = session.getTransport("smtp");
String username = null;
String password = null;
if (emailSetting.isAuthenticated()) {
username = emailSetting.getUsername();
password = emailSetting.getPassword();
}
transport.connect(emailSetting.getSmtpUrl(), emailSetting.getSmtpPort(), username,
password);
transport.close();
return true;
} catch (Throwable throwable) {
return false;
}
}
示例5: sendToAdmin
import javax.mail.Transport; //导入方法依赖的package包/类
@Override
public boolean sendToAdmin(final String institutionEmailAddress, final String applicationMessage) {
String[] to = new String[]{"[email protected]"};
setupProperties();
Session session = Session.getDefaultInstance(properties);
MimeMessage message = new MimeMessage(session);
try {
message.setFrom(new InternetAddress(username));
InternetAddress[] toAddress = new InternetAddress[to.length];
// To get the array of addresses
for (int i = 0; i < to.length; i++) {
toAddress[i] = new InternetAddress(to[i]);
}
for (int i = 0; i < toAddress.length; i++) {
message.addRecipient(Message.RecipientType.TO, toAddress[i]);
}
message.setSubject(APPLICATION_SUBJECT);
message.setText(applicationBody + "Email: " + institutionEmailAddress + "\nMessage: " + applicationMessage);
Transport transport = session.getTransport("smtp");
transport.connect(host, username, password);
transport.sendMessage(message, message.getAllRecipients());
transport.close();
LOGGER.info("Email sent to Admin");
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
示例6: sendFeedBackMail
import javax.mail.Transport; //导入方法依赖的package包/类
/**
* 发送反馈邮件
* @param detail
* @throws UnsupportedEncodingException
* @throws MessagingException
*/
public void sendFeedBackMail(String detail) throws UnsupportedEncodingException, MessagingException {
MimeMessage message = createFeedBackMsg(session,myEmailAccount,detail);
Transport transport = session.getTransport();
transport.connect(myEmailAccount, myEmailPassword);
transport.sendMessage(message, message.getAllRecipients());
transport.close();
}
示例7: sendTokenMail
import javax.mail.Transport; //导入方法依赖的package包/类
@Override
public boolean sendTokenMail(final String[] to, final String contractAddress, final String artifactId,
final String registryContract) {
setupProperties();
Session session = Session.getDefaultInstance(properties);
MimeMessage message = new MimeMessage(session);
try {
message.setFrom(new InternetAddress(username));
InternetAddress[] toAddress = new InternetAddress[to.length];
// To get the array of addresses
for (int i = 0; i < to.length; i++) {
toAddress[i] = new InternetAddress(to[i]);
}
for (int i = 0; i < toAddress.length; i++) {
message.addRecipient(Message.RecipientType.TO, toAddress[i]);
}
message.setSubject(TOKEN_SUBJECT);
message.setText(tokenBody + contractAddress + "\nArtifact ID: " + artifactId
+ "\n\nBelow is the Unilog Registry. Add this into the verifiers portal if you need to"
+ " verify a token: \n" + registryContract);
Transport transport = session.getTransport("smtp");
transport.connect(host, username, password);
transport.sendMessage(message, message.getAllRecipients());
transport.close();
LOGGER.info("Token email has been sent");
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
示例8: sendout
import javax.mail.Transport; //导入方法依赖的package包/类
/**
* 发送邮件
*/
public boolean sendout() {
try {
mimeMsg.setContent(mp);
mimeMsg.saveChanges();
logger.info(Resources.getMessage("EMAIL.SENDING"));
Session mailSession = Session.getInstance(props, new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
if (userkey == null || "".equals(userkey.trim())) {
return null;
}
return new PasswordAuthentication(username, userkey);
}
});
Transport transport = mailSession.getTransport("smtp");
transport.connect((String) props.get("mail.smtp.host"), username, password);
// 设置发送日期
mimeMsg.setSentDate(new Date());
// 发送
transport.sendMessage(mimeMsg, mimeMsg.getRecipients(Message.RecipientType.TO));
if (mimeMsg.getRecipients(Message.RecipientType.CC) != null) {
transport.sendMessage(mimeMsg, mimeMsg.getRecipients(Message.RecipientType.CC));
}
logger.info(Resources.getMessage("EMAIL.SEND_SUCC"));
transport.close();
return true;
} catch (Exception e) {
logger.error(Resources.getMessage("EMAIL.SEND_ERR"), e);
return false;
}
}
示例9: destroyObject
import javax.mail.Transport; //导入方法依赖的package包/类
/**
* Disconnects the pooled {@link Transport} object.
*
* @param key {@link URLName} containing the connection details.
* @param object Pooled {@link Transport}
*/
@Override
public void destroyObject(Object key, Object object) throws Exception
{
if (object instanceof Transport == false)
{
throw new IllegalArgumentException("Unexpected object type");
}
log.debug("Destroying Transpaort");
Transport transport = (Transport)object;
transport.close();
}
示例10: authenticateAndLoadConfiguration
import javax.mail.Transport; //导入方法依赖的package包/类
/** Test smtp authentication configuration.
*
* @param smtpConfiguration
* @throws MessagingException
* @throws ConfigurationException
*/
public void authenticateAndLoadConfiguration(EmailConfigurationDTO smtpConfiguration) throws MessagingException, ConfigurationException {
Transport transport = getSession().getTransport(SMTP_PROTOCOL);
try {
transport.connect(smtpConfiguration.getHost(), smtpConfiguration.getPort(), smtpConfiguration.getUserName(),
smtpConfiguration.getPassword());
} finally {
transport.close();
}
updateMailSenderConfig();
}
示例11: connect
import javax.mail.Transport; //导入方法依赖的package包/类
public static Boolean connect(Properties props)
throws MessagingException, IOException {
Session session = Session.getInstance(props, new javax.mail.Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(
props.getProperty("username"),
props.getProperty("password"));
}
});
Transport transport = session.getTransport("smtp");
transport.connect();
transport.close();
return true;
}
示例12: sendout
import javax.mail.Transport; //导入方法依赖的package包/类
/**
* 发送邮件
*
* @param name String
* @param pass String
*/
public boolean sendout() {
try {
mimeMsg.setContent(mp);
mimeMsg.saveChanges();
logger.info(Resources.getMessage("EMAIL.SENDING"));
Session mailSession = Session.getInstance(props, new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
if (userkey == null || "".equals(userkey.trim())) {
return null;
}
return new PasswordAuthentication(username, userkey);
}
});
Transport transport = mailSession.getTransport("smtp");
transport.connect((String) props.get("mail.smtp.host"), username, password);
// 设置发送日期
mimeMsg.setSentDate(new Date());
// 发送
transport.sendMessage(mimeMsg, mimeMsg.getRecipients(Message.RecipientType.TO));
if (mimeMsg.getRecipients(Message.RecipientType.CC) != null) {
transport.sendMessage(mimeMsg, mimeMsg.getRecipients(Message.RecipientType.CC));
}
logger.info(Resources.getMessage("EMAIL.SEND_SUCC"));
transport.close();
return true;
} catch (Exception e) {
logger.error(Resources.getMessage("EMAIL.SEND_ERR"), e);
return false;
}
}
示例13: sendEmail
import javax.mail.Transport; //导入方法依赖的package包/类
/**
* Versendet die EMail.
*
* @throws MessagingException -
*/
public void sendEmail() throws MessagingException {
Transport transport = mailSession.getTransport("smtp");
String emailHost = "smtp.gmail.com";
transport.connect(emailHost, fromEmail, fromPassword);
transport.sendMessage(emailMessage, emailMessage.getAllRecipients());
transport.close();
}
示例14: send
import javax.mail.Transport; //导入方法依赖的package包/类
/**
* @Title: send
* @Description: TODO(发送带附件的邮件)
* @author [email protected] (苟志强)
* @date 2017-6-6 下午4:29:56
* @param to 接收用户账户
* @param title 邮件标题
* @param content 邮件内容
* @param affix 附件路径
* @param affixName 发送后显示名称
* @return 是否发送成功
*/
public static boolean send(String to,String title,String content,String affix,String affixName) {
Properties props = new Properties();
//设置发送邮件的邮件服务器的属性(这里使用网易的smtp服务器)
props.put("mail.smtp.host", host);
//需要经过授权,也就是有户名和密码的校验,这样才能通过验证
props.put("mail.smtp.auth", "true");
//用刚刚设置好的props对象构建一个session
Session session = Session.getDefaultInstance(props);
//有了这句便可以在发送邮件的过程中在console处显示过程信息,供调试使
//用(你可以在控制台(console)上看到发送邮件的过程)
session.setDebug(true);
//用session为参数定义消息对象
MimeMessage message = new MimeMessage(session);
try{
//加载发件人地址
message.setFrom(new InternetAddress(from));
//加载收件人地址
message.addRecipient(Message.RecipientType.TO,new InternetAddress(to));
//加载标题
message.setSubject(title);
// 向multipart对象中添加邮件的各个部分内容,包括文本内容和附件
Multipart multipart = new MimeMultipart();
//设置邮件的文本内容
BodyPart contentPart = new MimeBodyPart();
contentPart.setText(content);
multipart.addBodyPart(contentPart);
//添加附件
if(affix!=null&&!"".equals(affix)&&affixName!=null&&!"".equals(affixName)){
BodyPart messageBodyPart= new MimeBodyPart();
DataSource source = new FileDataSource(affix);
//添加附件的内容
messageBodyPart.setDataHandler(new DataHandler(source));
//添加附件的标题
messageBodyPart.setFileName(MimeUtility.encodeText(affixName));
multipart.addBodyPart(messageBodyPart);
}
//将multipart对象放到message中
message.setContent(multipart);
//保存邮件
message.saveChanges();
// 发送邮件
Transport transport = session.getTransport("smtp");
//连接服务器的邮箱
transport.connect(host, user, pwd);
//把邮件发送出去
transport.sendMessage(message, message.getAllRecipients());
transport.close();
return true;
}catch(Exception e){
e.printStackTrace();
return false;
}
}
示例15: sendAlertEmail
import javax.mail.Transport; //导入方法依赖的package包/类
public void sendAlertEmail(String alert) throws MessagingException{
String host = "smtp.gmail.com";
String from = "[email protected]";
String pass = "3inst3in?";
Properties props = System.getProperties();
props.put("mail.smtp.starttls.enable", "true"); // added this line
props.put("mail.smtp.host", host);
props.put("mail.smtp.user", from);
props.put("mail.smtp.password", pass);
props.put("mail.smtp.port", "587");
props.put("mail.smtp.auth", "true");
Session session = Session.getDefaultInstance(props, null);
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
InternetAddress[] toAddress = new InternetAddress[alert_recipients.length];
// To get the array of addresses
for( int i=0; i < alert_recipients.length; i++ ) { // changed from a while loop
toAddress[i] = new InternetAddress(alert_recipients[i]);
}
//System.out.println(Message.RecipientType.TO);
for( int i=0; i < toAddress.length; i++) { // changed from a while loop
message.addRecipient(Message.RecipientType.TO, toAddress[i]);
}
message.setSubject("WARNING Something went wrong in the Einstein tunnel");
message.setText(alert);
Transport transport = session.getTransport("smtp");
transport.connect(host, from, pass);
transport.sendMessage(message, message.getAllRecipients());
transport.close();
}