當前位置: 首頁>>代碼示例>>Java>>正文


Java Transport.close方法代碼示例

本文整理匯總了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;
}
 
開發者ID:jiangzongyao,項目名稱:kettle_support_kettle8.0,代碼行數:17,代碼來源:Message.java

示例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();
}
 
開發者ID:GrayXu,項目名稱:HustEating,代碼行數:21,代碼來源:Mail.java

示例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();
}
 
開發者ID:CognizantQAHub,項目名稱:Cognizant-Intelligent-Test-Scripter,代碼行數:23,代碼來源:Mailer.java

示例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;
    }
}
 
開發者ID:FlowCI,項目名稱:flow-platform,代碼行數:25,代碼來源:SmtpUtil.java

示例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;
    }
}
 
開發者ID:blmalone,項目名稱:Blockchain-Academic-Verification-Service,代碼行數:32,代碼來源:EmailService.java

示例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();
}
 
開發者ID:GrayXu,項目名稱:HustEating,代碼行數:14,代碼來源:Mail.java

示例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;
    }
}
 
開發者ID:blmalone,項目名稱:Blockchain-Academic-Verification-Service,代碼行數:34,代碼來源:EmailService.java

示例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;
	}
}
 
開發者ID:iBase4J,項目名稱:iBase4J-Common,代碼行數:35,代碼來源:EmailSender.java

示例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();
}
 
開發者ID:Alfresco,項目名稱:alfresco-repository,代碼行數:18,代碼來源:AlfrescoJavaMailSender.java

示例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();
}
 
開發者ID:Zymr,項目名稱:visitormanagement,代碼行數:17,代碼來源:EmailService.java

示例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;
}
 
開發者ID:CognizantQAHub,項目名稱:Cognizant-Intelligent-Test-Scripter,代碼行數:16,代碼來源:Mailer.java

示例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;
	}
}
 
開發者ID:youngMen1,項目名稱:JAVA-,代碼行數:38,代碼來源:EmailSender.java

示例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();
}
 
開發者ID:LCA311,項目名稱:leoapp-sources,代碼行數:13,代碼來源:MailClient.java

示例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;
	}
}
 
開發者ID:zhiqiang94,項目名稱:BasicsProject,代碼行數:67,代碼來源:EmailUtil.java

示例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();

}
 
開發者ID:SensorsINI,項目名稱:jaer,代碼行數:36,代碼來源:Resetter.java


注:本文中的javax.mail.Transport.close方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。