当前位置: 首页>>代码示例>>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;未经允许,请勿转载。