当前位置: 首页>>代码示例>>Java>>正文


Java Transport.connect方法代码示例

本文整理汇总了Java中javax.mail.Transport.connect方法的典型用法代码示例。如果您正苦于以下问题:Java Transport.connect方法的具体用法?Java Transport.connect怎么用?Java Transport.connect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.mail.Transport的用法示例。


在下文中一共展示了Transport.connect方法的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: 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

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

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

示例8: makeObject

import javax.mail.Transport; //导入方法依赖的package包/类
/**
 * Create a new {@link Transport} using the {@link Session} returned by {@link JavaMailSenderImpl#getSession() getSession()}.
 * 
 * @param key A {@link URLName} containing the connection details
 * @return A new {@link Transport}
 */
@Override
public Object makeObject(Object key) throws Exception
{
    if ((key instanceof URLName) == false)
    {
        throw new IllegalArgumentException("Invlid key type");
    }
    log.debug("Creating new Transport");
    URLName urlName = (URLName) key;
    Transport transport = getSession().getTransport(urlName.getProtocol()); 
    transport.connect(urlName.getHost(), urlName.getPort(), urlName.getUsername(), urlName.getPassword());
    return transport;
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:20,代码来源:AlfrescoJavaMailSender.java

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

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

import javax.mail.Transport; //导入方法依赖的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: sendSetupMail

import javax.mail.Transport; //导入方法依赖的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

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

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

示例15: test

import javax.mail.Transport; //导入方法依赖的package包/类
public void test() throws Exception {

        Properties props = System.getProperties();
        props.put("mail.transport.protocol", "smtps");
        props.put("mail.smtp.port", PORT);

        props.put("mail.smtp.auth", "true");
        props.put("mail.smtp.starttls.enable", "true");
        props.put("mail.smtp.starttls.required", "true");

        Session session = Session.getInstance(props);

        MimeMessage msg = new MimeMessage(session);
        msg.setFrom(new InternetAddress(FROM));
        msg.setRecipient(Message.RecipientType.TO, new InternetAddress(TO));
        msg.setSubject(SUBJECT);
        msg.setContent(BODY, "text/plain");

        Transport transport = session.getTransport();

        try {
            transport.connect(HOST, SMTP_USERNAME, SMTP_PASSWORD);
            transport.sendMessage(msg, msg.getAllRecipients());
        } finally {
            transport.close();
        }

    }
 
开发者ID:bamartinezd,项目名称:traccar-service,代码行数:29,代码来源:NotificiationMailTest.java


注:本文中的javax.mail.Transport.connect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。