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


Java Session.getTransport方法代碼示例

本文整理匯總了Java中javax.mail.Session.getTransport方法的典型用法代碼示例。如果您正苦於以下問題:Java Session.getTransport方法的具體用法?Java Session.getTransport怎麽用?Java Session.getTransport使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.mail.Session的用法示例。


在下文中一共展示了Session.getTransport方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: iMessage

import javax.mail.Session; //導入方法依賴的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: sendToAdmin

import javax.mail.Session; //導入方法依賴的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

示例3: sendout

import javax.mail.Session; //導入方法依賴的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

示例4: sendout

import javax.mail.Session; //導入方法依賴的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:guokezheng,項目名稱:automat,代碼行數:38,代碼來源:EmailSender.java

示例5: sendTokenMail

import javax.mail.Session; //導入方法依賴的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

示例6: sendSetupMail

import javax.mail.Session; //導入方法依賴的package包/類
@Override
public boolean sendSetupMail(final String[] to, final String code, final String subject, final String body) {
    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]);
        }
        if (subject == null || body == null) {
            message.setSubject(SETUP_SUBJECT);
            message.setText(setupBody + code);
        } else {
            message.setSubject(subject);
            message.setText(body + code);
        }

        Transport transport = session.getTransport("smtp");
        transport.connect(host, username, password);
        transport.sendMessage(message, message.getAllRecipients());
        transport.close();
        LOGGER.info("Setup email has been sent.");
        return true;
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}
 
開發者ID:blmalone,項目名稱:Blockchain-Academic-Verification-Service,代碼行數:37,代碼來源:EmailService.java

示例7: getTransport

import javax.mail.Session; //導入方法依賴的package包/類
/**
 * Obtain a Transport object from the given JavaMail Session,
 * using the configured protocol.
 * <p>Can be overridden in subclasses, e.g. to return a mock Transport object.
 * @see javax.mail.Session#getTransport(String)
 * @see #getProtocol()
 */
protected Transport getTransport(Session session) throws NoSuchProviderException {
	String protocol	= getProtocol();
	if (protocol == null) {
		protocol = session.getProperty("mail.transport.protocol");
		if (protocol == null) {
			protocol = DEFAULT_PROTOCOL;
		}
	}
	return session.getTransport(protocol);
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:18,代碼來源:JavaMailSenderImpl.java

示例8: sendAlertEmail

import javax.mail.Session; //導入方法依賴的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

示例9: connect

import javax.mail.Session; //導入方法依賴的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

示例10: sendAccountCreatedMail

import javax.mail.Session; //導入方法依賴的package包/類
@Override
public boolean sendAccountCreatedMail(final String[] to, final String email) {
    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(DETAILS_SUBJECT);
        message.setText(detailsBody + "username: " + email);
        Transport transport = session.getTransport("smtp");
        transport.connect(host, username, password);
        transport.sendMessage(message, message.getAllRecipients());
        transport.close();
        LOGGER.info("Login details email has been sent.");
        return true;
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}
 
開發者ID:blmalone,項目名稱:Blockchain-Academic-Verification-Service,代碼行數:31,代碼來源:EmailService.java

示例11: send

import javax.mail.Session; //導入方法依賴的package包/類
/**
 * 發送郵件
 * 
 * @param email-收件人
 * @throws Exception
 * @return new password
 */
public static String send(String email, String username) throws Exception {

	String pwd = getRandomString(6);
	
	// 2. 根據配置創建會話對象, 用於和郵件服務器交互
	Session session = Session.getDefaultInstance(props);
	session.setDebug(true); // 設置為debug模式, 可以查看詳細的發送 log

	// 3. 創建一封郵件
	MimeMessage message = createMimeMessage(session, myEmailAccount, email, username,pwd);

	// 4. 根據 Session 獲取郵件傳輸對象
	Transport transport = session.getTransport();

	// 5. 使用 郵箱賬號 和 密碼 連接郵件服務器, 這裏認證的郵箱必須與 message 中的發件人郵箱一致, 否則報錯
	//
	// PS_01: 成敗的判斷關鍵在此一句, 如果連接服務器失敗, 都會在控製台輸出相應失敗原因的 log,
	// 仔細查看失敗原因, 有些郵箱服務器會返回錯誤碼或查看錯誤類型的鏈接, 根據給出的錯誤
	// 類型到對應郵件服務器的幫助網站上查看具體失敗原因。
	//
	// PS_02: 連接失敗的原因通常為以下幾點, 仔細檢查代碼:
	// (1) 郵箱沒有開啟 SMTP 服務;
	// (2) 郵箱密碼錯誤, 例如某些郵箱開啟了獨立密碼;
	// (3) 郵箱服務器要求必須要使用 SSL 安全連接;
	// (4) 請求過於頻繁或其他原因, 被郵件服務器拒絕服務;
	// (5) 如果以上幾點都確定無誤, 到郵件服務器網站查找幫助。
	//
	// PS_03: 仔細看log, 認真看log, 看懂log, 錯誤原因都在log已說明。
	transport.connect(myEmailAccount, myEmailPassword);

	// 6. 發送郵件, 發到所有的收件地址, message.getAllRecipients() 獲取到的是在創建郵件對象時添加的所有收件人,
	// 抄送人, 密送人
	transport.sendMessage(message, message.getAllRecipients());

	// 7. 關閉連接
	transport.close();
	
	return pwd;
}
 
開發者ID:miracle857,項目名稱:weibo,代碼行數:47,代碼來源:Mail.java

示例12: sendMail

import javax.mail.Session; //導入方法依賴的package包/類
/**
 * Send mail.
 *
 * @param from
 *            Sender's email ID needs to be mentioned
 * @param to
 *            Recipient's email ID needs to be mentioned.
 * @param subject
 *            the subject
 * @throws MessagingException
 */
public void sendMail(String from, String to, String subject, String body) throws MessagingException {

	// Get system properties
	Properties properties = System.getProperties();

	// Setup mail server
	properties.setProperty("mail.smtp.host", host);
	properties.setProperty("mail.smtp.port", Integer.toString(port));

	// Get the default Session object.
	Session session = Session.getDefaultInstance(properties);

	Transport transport = null;
	try {
		transport = session.getTransport();

		// Create a default MimeMessage object.
		MimeMessage message = new MimeMessage(session);

		// Set From: header field of the header.
		message.setFrom(new InternetAddress(from));

		// Set To: header field of the header.
		message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));

		// Set Subject: header field
		message.setSubject(subject);

		// Now set the actual message
		message.setText(body);

		// Send message
		transport.send(message);
		System.out.println("Sent message successfully....");
	} finally {
		if (transport != null) {
			transport.close();
		}
	}

}
 
開發者ID:sleroy,項目名稱:fakesmtp-junit-runner,代碼行數:53,代碼來源:MailSender.java

示例13: sendPassword

import javax.mail.Session; //導入方法依賴的package包/類
public static void sendPassword(String receiveMailAccount, String password) throws Exception {

        Properties props = new Properties();                    
        props.setProperty("mail.transport.protocol", "smtp");  

        props.setProperty("mail.smtp.host", myEmailSMTPHost);
        props.setProperty("mail.smtp.auth", "true"); 
        

        Session session = Session.getDefaultInstance(props);
        session.setDebug(true);                         
   
        MimeMessage message = createMimeMessage(session, myEmailAccount, receiveMailAccount, password);

     
        Transport transport = session.getTransport();

        transport.connect(myEmailAccount, myEmailPassword);


        transport.sendMessage(message, message.getAllRecipients());

        transport.close();
    }
 
開發者ID:632team,項目名稱:EasyHousing,代碼行數:25,代碼來源:Tool.java

示例14: sendMail

import javax.mail.Session; //導入方法依賴的package包/類
public boolean sendMail(String to,String otp) throws MessagingException 
{
	String host="smtp.gmail.com";
	String username="";//emailid
	String password="";//emailid password
	String from=" ";// email from which u have to send
	String subject="One Time Password";
	String body="Your One Time passsword is "+otp;
	
	boolean sessionDebug=false;
	
	Properties props=System.getProperties();
	props.put("mail.host",host);
	props.put("mail.transport.protocol","smtp");
	props.put("mail.smtp.starttls.enable","true");
	props.put("mail.smtp.auth", "true");
	props.put("mail.smtp.debug", "true");
	props.put("mail.smtp.socketFactory.port", "465");
	props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
	props.put("mail.smtp.socketFactory.fallback", "false");
	props.put("mail.smtp.host", "smtp.gmail.com");
	props.put("mail.smtp.port", "25"); 
	
	Session mailSession=Session.getDefaultInstance(props,null);
	mailSession.setDebug(sessionDebug);
	
	Message msg=new MimeMessage(mailSession);
	msg.setFrom(new InternetAddress(from));
	InternetAddress [] address={new InternetAddress(to)};
	msg.setRecipients(Message.RecipientType.TO,address);
	msg.setSubject(subject);
	msg.setSentDate(new Date());
	msg.setText(body);

	Transport tr=mailSession.getTransport("smtp");
	tr.connect(host,username,password);
	msg.saveChanges();
	tr.sendMessage(msg,msg.getAllRecipients());
	tr.close();
	//Transport.send(msg);
	return true;
}
 
開發者ID:nishittated,項目名稱:OnlineElectionVotingSystem,代碼行數:43,代碼來源:PasswordMail.java

示例15: sendMail1

import javax.mail.Session; //導入方法依賴的package包/類
public boolean sendMail1(String to,String passwrd, String link) throws MessagingException
{
	String host="smtp.gmail.com";
	String username="	 ";//emailid
	String password="";//emailid password
	String from=" ";// email from which u have to send
	String subject="Website Password";
	String body="Your website password is "+passwrd+"  Please click to reset "+link;
	boolean sessionDebug=false;
	
	Properties props=System.getProperties();
	props.put("mail.host",host);
	props.put("mail.transport.protocol","smtp");
	props.put("mail.smtp.starttls.enable","true");
	props.put("mail.smtp.auth", "true");
	props.put("mail.smtp.debug", "true");
	props.put("mail.smtp.socketFactory.port", "465");
	props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
	props.put("mail.smtp.socketFactory.fallback", "false");
	props.put("mail.smtp.host", "smtp.gmail.com");
	props.put("mail.smtp.port", "25"); 
	
	Session mailSession=Session.getDefaultInstance(props,null);
	mailSession.setDebug(sessionDebug);

	Message msg=new MimeMessage(mailSession);
	msg.setFrom(new InternetAddress(from));
	
	InternetAddress [] address={new InternetAddress(to)};
	msg.setRecipients(Message.RecipientType.TO,address);
	msg.setSubject(subject);
	msg.setSentDate(new Date());
	msg.setText(body);
	
	Transport tr=mailSession.getTransport("smtp");
	tr.connect(host,username,password);
	msg.saveChanges();
	tr.sendMessage(msg,msg.getAllRecipients());
	tr.close();
			//Transport.send(msg);
	return true;
}
 
開發者ID:nishittated,項目名稱:OnlineElectionVotingSystem,代碼行數:43,代碼來源:PasswordMail.java


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