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


Java Transport類代碼示例

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


Transport類屬於javax.mail包,在下文中一共展示了Transport類的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: sendMail

import javax.mail.Transport; //導入依賴的package包/類
public static void sendMail(String host, int port, String username, String password, String recipients,
		String subject, String content, String from) throws AddressException, MessagingException {
	
	Properties props = new Properties();
	props.put("mail.smtp.auth", "true");
	props.put("mail.smtp.starttls.enable", "true");
	props.put("mail.smtp.host", host);
	props.put("mail.smtp.port", port);

	Session session = Session.getInstance(props, new javax.mail.Authenticator() {
		protected PasswordAuthentication getPasswordAuthentication() {
			return new PasswordAuthentication(username, password);
		}
	});

	Message message = new MimeMessage(session);
	message.setFrom(new InternetAddress(from));
	message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(recipients));
	message.setSubject(subject);
	message.setText(content);

	Transport.send(message);
}
 
開發者ID:bndynet,項目名稱:web-framework-for-java,代碼行數:24,代碼來源:MailHelper.java

示例3: sendTextMail

import javax.mail.Transport; //導入依賴的package包/類
public boolean sendTextMail(MailSenderInfo mailInfo) {
    MyAuthenticator authenticator = null;
    Properties pro = mailInfo.getProperties();
    if (mailInfo.isValidate()) {
        authenticator = new MyAuthenticator(mailInfo.getUserName(), mailInfo.getPassword());
    }
    try {
        Message mailMessage = new MimeMessage(Session.getInstance(pro, authenticator));
        mailMessage.setFrom(new InternetAddress(mailInfo.getFromAddress()));
        mailMessage.setRecipient(Message.RecipientType.TO, new InternetAddress(mailInfo.getToAddress()));
        mailMessage.setSubject(mailInfo.getSubject());
        mailMessage.setSentDate(new Date());
        mailMessage.setText(mailInfo.getContent());
        Transport.send(mailMessage);
        return true;
    } catch (MessagingException ex) {
        ex.printStackTrace();
        return false;
    }
}
 
開發者ID:JamesLiAndroid,項目名稱:AndroidKillerService,代碼行數:21,代碼來源:SimpleMailSender.java

示例4: sendMsg

import javax.mail.Transport; //導入依賴的package包/類
public boolean sendMsg(String recipient, String subject, String content)
		throws MessagingException {
	// Create a mail object
	Session session = Session.getInstance(props, new Authenticator() {
		// Set the account information session,transport will send mail
		@Override
		protected PasswordAuthentication getPasswordAuthentication() {
			return new PasswordAuthentication(Constants.MAIL_USERNAME, Constants.MAIL_PASSWORD);
		}
	});
	session.setDebug(true);
	Message msg = new MimeMessage(session);
	try {
		msg.setSubject(subject);			//Set the mail subject
		msg.setContent(content,"text/html;charset=utf-8");
		msg.setFrom(new InternetAddress(Constants.MAIL_USERNAME));			//Set the sender
		msg.setRecipient(RecipientType.TO, new InternetAddress(recipient));	//Set the recipient
		Transport.send(msg);
		return true;
	} catch (Exception ex) {
		ex.printStackTrace();
		System.out.println(ex.getMessage());
		return false;
	}

}
 
開發者ID:ICT-BDA,項目名稱:EasyML,代碼行數:27,代碼來源:JavaMail.java

示例5: 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

示例6: completeClientSend

import javax.mail.Transport; //導入依賴的package包/類
public void completeClientSend(String mailServer, String... credentials) throws AddressException, MessagingException {
	if (credentials != null && credentials.length > 1) {
		// Step1
		logger.info("\n 1st ===> setup Mail Server Properties..");
		logger.info("Mail Server Properties have been setup successfully..");
		// Step2
		logger.info("\n\n 2nd ===> get Mail .");
		getMailSession = getDefaultInstance(mailServerProperties, null);
		generateMailMessage = new MimeMessage(getMailSession);
		generateMailMessage.addRecipient(TO, new InternetAddress("[email protected]"));
		generateMailMessage.addRecipient(CC, new InternetAddress("[email protected]"));
		generateMailMessage.setSubject("Greetings from Vige..");
		String emailBody = "Test email by Vige.it JavaMail API example. " + "<br><br> Regards, <br>Vige Admin";
		generateMailMessage.setContent(emailBody, "text/html");
		logger.info("Mail Session has been created successfully..");
		// Step3
		logger.info("\n\n 3rd ===> Get Session and Send mail");
		Transport transport = getMailSession.getTransport("smtp");
		// Enter your correct gmail UserID and Password
		// if you have 2FA enabled then provide App Specific Password
		transport.connect(mailServer, credentials[0], credentials[1]);
		transport.sendMessage(generateMailMessage, generateMailMessage.getAllRecipients());
		transport.close();
	}
}
 
開發者ID:PacktPublishing,項目名稱:Mastering-Java-EE-Development-with-WildFly,代碼行數:26,代碼來源:SendMail.java

示例7: sendTextEmail

import javax.mail.Transport; //導入依賴的package包/類
public static void sendTextEmail(String to, String from, String subject, String msg, final ServerSetup setup) {
    try {
        Session session = getSession(setup);

        Address[] tos = new javax.mail.Address[0];
        tos = new InternetAddress[]{new InternetAddress(to)};
        Address[] froms = new InternetAddress[]{new InternetAddress(from)};
        MimeMessage mimeMessage = new MimeMessage(session);
        mimeMessage.setSubject(subject);
        mimeMessage.setFrom(froms[0]);

        mimeMessage.setText(msg);
        Transport.send(mimeMessage, tos);
    } catch (Throwable e) {
        throw new RuntimeException(e);
    }
}
 
開發者ID:Alfresco,項目名稱:alfresco-greenmail,代碼行數:18,代碼來源:GreenMailUtil.java

示例8: sendEmail

import javax.mail.Transport; //導入依賴的package包/類
private static void sendEmail(String fromEmail, String toEmail, String subject, String body, boolean html)
throws MessagingException{
	MimeMessage message = new MimeMessage(MAILING_SESSION);
	message.setFrom(new InternetAddress(fromEmail));
	InternetAddress[] addresses = InternetAddress.parse(toEmail);//one or more addresses
	message.addRecipients(RecipientType.TO, addresses);
	message.setReplyTo(addresses);
	message.setSubject(subject);
	String subType;
	if(html){
		subType = "html";
	}else{
		subType = "plain";
	}
	message.setText(body, "UTF-8", subType);
	Transport.send(message);
}
 
開發者ID:hotpads,項目名稱:datarouter,代碼行數:18,代碼來源:DatarouterEmailTool.java

示例9: sendEmail

import javax.mail.Transport; //導入依賴的package包/類
@Override
public void sendEmail(String address, String subject, String content, Map<String, String> headers) throws Exception {
	Session session = MailUtilities.makeSession();
	if (session == null) {
		// LogService.getRoot().warning("Unable to create mail session. Not sending mail to "+address+".");
		LogService.getRoot().log(Level.WARNING, "com.rapidminer.tools.MailSenderSMTP.creating_mail_session_error",
				address);
	}
	MimeMessage msg = new MimeMessage(session);
	msg.setRecipients(Message.RecipientType.TO, address);
	msg.setFrom();
	msg.setSubject(subject, "UTF-8");
	msg.setSentDate(new Date());
	msg.setText(content, "UTF-8");

	if (headers != null) {
		for (Entry<String, String> header : headers.entrySet()) {
			msg.setHeader(header.getKey(), header.getValue());
		}
	}
	Transport.send(msg);
}
 
開發者ID:transwarpio,項目名稱:rapidminer,代碼行數:23,代碼來源:MailSenderSMTP.java

示例10: send

import javax.mail.Transport; //導入依賴的package包/類
public void send(String addresses, String topic, String textMessage) {

		try {
			session.getProperties().put("mail.smtp.port", 25000);
			Message message = new MimeMessage(session);
			message.setRecipients(TO, InternetAddress.parse(addresses));
			message.setSubject(topic);
			message.setText(textMessage);

			Transport.send(message);
			logger.info("sent mail with resource!");

		} catch (MessagingException e) {
			logger.log(WARNING, "Cannot send mail", e);
		}
	}
 
開發者ID:PacktPublishing,項目名稱:Mastering-Java-EE-Development-with-WildFly,代碼行數:17,代碼來源:SendMailWithResource.java

示例11: sendAttachMail

import javax.mail.Transport; //導入依賴的package包/類
public boolean sendAttachMail(MailSenderInfo mailInfo) {
    MyAuthenticator authenticator = null;
    Properties pro = mailInfo.getProperties();
    if (mailInfo.isValidate()) {
        authenticator = new MyAuthenticator(mailInfo.getUserName(), mailInfo.getPassword());
    }
    try {
        Message mailMessage = new MimeMessage(Session.getInstance(pro, authenticator));
        mailMessage.setFrom(new InternetAddress(mailInfo.getFromAddress()));
        mailMessage.setRecipient(Message.RecipientType.TO, new InternetAddress(mailInfo.getToAddress()));
        mailMessage.setSubject(mailInfo.getSubject());
        mailMessage.setSentDate(new Date());
        Multipart multi = new MimeMultipart();
        BodyPart textBodyPart = new MimeBodyPart();
        textBodyPart.setContent(mailInfo.getContent(), "text/html; charset=utf-8");
        multi.addBodyPart(textBodyPart);
        for (String path : mailInfo.getAttachFileNames()) {
            DataSource fds = new FileDataSource(path);
            BodyPart fileBodyPart = new MimeBodyPart();
            fileBodyPart.setDataHandler(new DataHandler(fds));
            fileBodyPart.setFileName(path.substring(path.lastIndexOf("/") + 1));
            multi.addBodyPart(fileBodyPart);
        }
        mailMessage.setContent(multi);
        mailMessage.saveChanges();
        Transport.send(mailMessage);
        return true;
    } catch (MessagingException ex) {
        ex.printStackTrace();
        return false;
    }
}
 
開發者ID:JamesLiAndroid,項目名稱:AndroidKillerService,代碼行數:33,代碼來源:SimpleMailSender.java

示例12: sendEmailWithOrder

import javax.mail.Transport; //導入依賴的package包/類
public static void sendEmailWithOrder(String text, String eMail, HttpServletRequest request) {
    try {
        Session session = EmailActions.authorizeWebShopEmail();

        Message msg = new MimeMessage(session);
        msg.setFrom(new InternetAddress(ApplicationProperties.SHOP_EMAIL));
        msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(eMail, false));
        msg.setSubject("Shop order");
        msg.setText(text);
        msg.setSentDate(new Date());
        Transport.send(msg);
    } catch (MessagingException e) {
        System.out.println("Error : " + e);
    }
}
 
開發者ID:xSzymo,項目名稱:Spring-web-shop-project,代碼行數:16,代碼來源:SendEmailUserAccount.java

示例13: sendHtmlEmail

import javax.mail.Transport; //導入依賴的package包/類
public void sendHtmlEmail(EmailObject email) throws Exception {
    // 創建Session實例對象
    Session session = Session.getInstance(props, new EmailAuthenticator());

    // 創建MimeMessage實例對象
    MimeMessage message = new MimeMessage(session);
    // 設置郵件主題
    message.setSubject(email.getEmailSubject(),"utf-8");
    // 設置發送人
    message.setFrom(new InternetAddress(from));
    // 設置發送時間
    message.setSentDate(new Date());
    // 設置收件人
    message.setRecipients(MimeMessage.RecipientType.TO, InternetAddress.parse(email.getToEmail()));
    // 設置html內容為郵件正文,指定MIME類型為text/html類型,並指定字符編碼為gbk
    message.setContent(email.getEmailContent(), "text/html;charset=utf-8");
    // 保存並生成最終的郵件內容
    message.saveChanges();
    // 發送郵件
    Transport.send(message);
    //記錄郵件發送日誌
    SendEmailLog sendEmailLog = new SendEmailLog();
    sendEmailLog.setToemail(email.getToEmail());
    sendEmailLog.setSubject(email.getEmailSubject());
    sendEmailLog.setSenddate(new Date());
    sendEmailLog.setContent(email.getEmailContent());
    sendEmailLogDao.insert(sendEmailLog);
}
 
開發者ID:NeilRen,項目名稱:NEILREN4J,代碼行數:29,代碼來源:EmailUtils.java

示例14: sendReport

import javax.mail.Transport; //導入依賴的package包/類
@Test
public void sendReport() throws MessagingException {

    mockStatic(Transport.class);

    expect(ReportConfigurator.getInstance()).andReturn(mockReportConfigurator);
    expect(mockReportConfigurator.getSmtpServerName()).andReturn("localhost");
    expect(mockReportConfigurator.getSmtpServerPort()).andReturn("25");
    expect(mockReportConfigurator.getAddressesTo()).andReturn(new String[]{ "userTo" });
    expect(mockReportConfigurator.getAddressesCc()).andReturn(new String[0]);
    expect(mockReportConfigurator.getAddressesBcc()).andReturn(new String[0]);
    expect(mockReportConfigurator.getAddressFrom()).andReturn("userFrom");

    Transport.send(isA(Message.class));

    replayAll();

    triggerRun();

    verifyAll();
}
 
開發者ID:Axway,項目名稱:ats-framework,代碼行數:22,代碼來源:Test_MailReportSender.java

示例15: errorOnSend

import javax.mail.Transport; //導入依賴的package包/類
@Test( expected = MailReportSendException.class)
public void errorOnSend() throws MessagingException {

    mockStatic(Transport.class);

    expect(ReportConfigurator.getInstance()).andReturn(mockReportConfigurator);
    expect(mockReportConfigurator.getSmtpServerName()).andReturn("localhost");
    expect(mockReportConfigurator.getSmtpServerPort()).andReturn("25");
    expect(mockReportConfigurator.getAddressesTo()).andReturn(new String[]{ "userTo" });
    expect(mockReportConfigurator.getAddressesCc()).andReturn(new String[0]);
    expect(mockReportConfigurator.getAddressesBcc()).andReturn(new String[0]);
    expect(mockReportConfigurator.getAddressFrom()).andReturn("userFrom");

    Transport.send(isA(Message.class));
    expectLastCall().andThrow(new MessagingException());

    replayAll();

    triggerRun();

    verifyAll();
}
 
開發者ID:Axway,項目名稱:ats-framework,代碼行數:23,代碼來源:Test_MailReportSender.java


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