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


Java HtmlEmail.setSmtpPort方法代码示例

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


在下文中一共展示了HtmlEmail.setSmtpPort方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: doSend

import org.apache.commons.mail.HtmlEmail; //导入方法依赖的package包/类
private void doSend(String recipient, String sender, Set<String> cc, String subject, String content,
                    EmailAttachment... attachments) throws EmailException {
    HtmlEmail email = new HtmlEmail();
    email.setCharset("utf-8");
    for (EmailAttachment attachment : attachments) {
        email.attach(attachment);
    }
    email.setHostName(HOST);
    email.setSmtpPort(PORT);
    email.setAuthenticator(new DefaultAuthenticator(USER, PWD));
    email.setSSLOnConnect(USE_SSL);
    email.setSubject(subject);
    email.addTo(recipient);
    email.setFrom(String.format("Exam <%s>", SYSTEM_ACCOUNT));
    email.addReplyTo(sender);
    for (String addr : cc) {
        email.addCc(addr);
    }
    email.setHtmlMsg(content);
    if (USE_MOCK) {
        mockSending(email, content, attachments);
    } else {
        email.send();
    }
}
 
开发者ID:CSCfi,项目名称:exam,代码行数:26,代码来源:EmailSenderImpl.java

示例2: send

import org.apache.commons.mail.HtmlEmail; //导入方法依赖的package包/类
public static void send(Mail mail) {
    HtmlEmail email = new HtmlEmail();
    try {
        email.setHostName(mail.getHost());
        email.setCharset(Config.UTF_8);
        email.addTo(mail.getReceiver());
        email.setFrom(mail.getSender(), mail.getName());
        email.setAuthentication(mail.getUsername(), mail.getPassword());
        email.setSubject(mail.getSubject());
        email.setMsg(mail.getMessage());
        email.setSmtpPort(mail.getSmtpPort());
        email.send();
    } catch (EmailException e) {
        e.printStackTrace();
    }
}
 
开发者ID:fku233,项目名称:MBLive,代码行数:17,代码来源:MailKit.java

示例3: sendCommonMail

import org.apache.commons.mail.HtmlEmail; //导入方法依赖的package包/类
/**
 * 发送普通邮件
 * 
 * @param toMailAddr
 *            收信人地址
 * @param subject
 *            email主题
 * @param message
 *            发送email信息
 */
public static void sendCommonMail(String toMailAddr, String subject,
		String message) {
	HtmlEmail hemail = new HtmlEmail();
	try {
		hemail.setHostName(getHost(from));
		hemail.setSmtpPort(getSmtpPort(from));
		hemail.setCharset(charSet);
		hemail.addTo(toMailAddr);
		hemail.setFrom(from, fromName);
		hemail.setAuthentication(username, password);
		hemail.setSubject(subject);
		hemail.setMsg(message);
		hemail.send();
		System.out.println("email send true!");
	} catch (Exception e) {
		e.printStackTrace();
		System.out.println("email send error!");
	}

}
 
开发者ID:EleTeam,项目名称:Shop-for-JavaWeb,代码行数:31,代码来源:SendMailUtil.java

示例4: getHtmlEmail

import org.apache.commons.mail.HtmlEmail; //导入方法依赖的package包/类
private HtmlEmail getHtmlEmail( String hostName, int port, String username, String password, boolean tls,
    String sender )
    throws EmailException
{
    HtmlEmail email = new HtmlEmail();
    email.setHostName( hostName );
    email.setFrom( sender, customizeTitle( DEFAULT_FROM_NAME ) );
    email.setSmtpPort( port );
    email.setStartTLSEnabled( tls );

    if ( username != null && password != null )
    {
        email.setAuthenticator( new DefaultAuthenticator( username, password ) );
    }

    return email;
}
 
开发者ID:dhis2,项目名称:dhis2-core,代码行数:18,代码来源:EmailMessageSender.java

示例5: getHtmlEmail

import org.apache.commons.mail.HtmlEmail; //导入方法依赖的package包/类
private HtmlEmail getHtmlEmail( String hostName, int port, String username, String password, boolean tls, String sender )
    throws EmailException
{
    HtmlEmail email = new HtmlEmail();
    email.setHostName( hostName );
    email.setFrom( defaultIfEmpty( sender, FROM_ADDRESS ), customizeTitle( DEFAULT_FROM_NAME ) );
    email.setSmtpPort( port );
    email.setStartTLSEnabled( tls );

    if ( username != null && password != null )
    {
        email.setAuthenticator( new DefaultAuthenticator( username, password ) );
    }

    return email;
}
 
开发者ID:ehatle,项目名称:AgileAlligators,代码行数:17,代码来源:EmailMessageSender.java

示例6: testSendEmail

import org.apache.commons.mail.HtmlEmail; //导入方法依赖的package包/类
@Test
public void testSendEmail() throws Exception {
	MockSMTPServer server = new MockSMTPServer();
	assertFalse(server.isRunning());
	server.start();
	assertTrue(server.isRunning());
	int port = server.getPort();
	assertTrue(port > 0);

	HtmlEmail email = new HtmlEmail();
	email.setHostName("localhost");
	email.setSmtpPort(port);

	email.setTextMsg("somemessage");
	email.setSubject("somesubj");
	email.setTo(Arrays.asList(InternetAddress.parse("[email protected]")));
	email.setFrom("[email protected]");

	email.send();

	assertEquals(1, server.getMessageCount());
	assertNotNull(server.getMessages());
	assertNotNull(server.getMessages().next());

	server.stop();
}
 
开发者ID:centic9,项目名称:commons-test,代码行数:27,代码来源:MockSMTPServerTest.java

示例7: sendEmail

import org.apache.commons.mail.HtmlEmail; //导入方法依赖的package包/类
public void sendEmail() {
	HtmlEmail email = new HtmlEmail();
	try {
		email.setHostName(emailHostName);
		email.setSmtpPort(smtpPort);
		email.setAuthenticator(new DefaultAuthenticator(emailLogin,
				emailPassword));
		email.setSSLOnConnect(emailSSL);
		email.setStartTLSEnabled(startTLS);
		email.setFrom(emailSender);
		email.setSubject(title);
		email.setHtmlMsg(htmlMessage);
		email.addTo(emailRecipient);
		email.send();
		System.out.println("Email sent: " + title);
	} catch (EmailException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
}
 
开发者ID:RobCubed,项目名称:ShipworksWeeklyReports,代码行数:21,代码来源:Email.java

示例8: sendEmail

import org.apache.commons.mail.HtmlEmail; //导入方法依赖的package包/类
/** Sends email according to the provided config. */
private static void sendEmail(SmtpConfiguration config, HtmlEmail email, String subject,
    String fromAddress, String toAddress) throws EmailException {
  if (config != null) {
    email.setSubject(subject);
    LOG.info("Sending email to {}", toAddress);
    email.setHostName(config.getSmtpHost());
    email.setSmtpPort(config.getSmtpPort());
    if (config.getSmtpUser() != null && config.getSmtpPassword() != null) {
      email.setAuthenticator(
          new DefaultAuthenticator(config.getSmtpUser(), config.getSmtpPassword()));
      email.setSSLOnConnect(true);
    }
    email.setFrom(fromAddress);
    for (String address : toAddress.split(EMAIL_ADDRESS_SEPARATOR)) {
      email.addTo(address);
    }
    email.send();
    LOG.info("Email sent with subject [{}] to address [{}]!", subject, toAddress);
  } else {
    LOG.error("No email config provided for email with subject [{}]!", subject);
  }
}
 
开发者ID:linkedin,项目名称:pinot,代码行数:24,代码来源:EmailHelper.java

示例9: sendWithHtml

import org.apache.commons.mail.HtmlEmail; //导入方法依赖的package包/类
@Override
public void sendWithHtml(String recipient, String subject, String content) throws SendMailException {
	Assert.hasText(recipient);
	Assert.hasText(subject);
	Assert.hasText(content);
	
	HtmlEmail email = new HtmlEmail();
	email.setHostName(host);
	email.setAuthenticator(new DefaultAuthenticator(loginName, loginPassword));
	email.setSmtpPort(port);
	email.setTLS(tls);

	try {
		email.setCharset("UTF-8"); // specify the charset.
		email.setFrom(fromAddress, fromName);
		email.setSubject(subject);
		email.setHtmlMsg(content);
		//email.setMsg(""); // can set plain text either
		email.addTo(recipient);
		email.send();
	} catch (EmailException e) {
		throw new SendMailException(
				String.format("Failed to send mail to %s.", recipient), e);
	}
}
 
开发者ID:ivarptr,项目名称:clobaframe,代码行数:26,代码来源:SmtpMailSender.java

示例10: send

import org.apache.commons.mail.HtmlEmail; //导入方法依赖的package包/类
/**
 * Send email with subject and message body.
 * @param subject the email subject.
 * @param body the email body.
 */
public void send(String subject, String body) {
    try {
        HtmlEmail email = new HtmlEmail();
        email.setHostName(configuration.getString(CONFKEY_REPORTS_MAILER_SMTP_HOST, "localhost"));
        email.setSmtpPort(configuration.getInt(CONFKEY_REPORTS_MAILER_SMTP_PORT, 465));
        email.setAuthenticator(new DefaultAuthenticator(
            configuration.getString(CONFKEY_REPORTS_MAILER_SMTP_USER, "anonymous"),
            configuration.getString(CONFKEY_REPORTS_MAILER_SMTP_PASS, "guest")
        ));
        email.setStartTLSEnabled(false);
        email.setSSLOnConnect(configuration.getBoolean(CONFKEY_REPORTS_MAILER_SMTP_SSL, true));
        email.setFrom(configuration.getString(CONFKEY_REPORTS_MAILER_SMTP_FROM, ""));
        email.setSubject(subject);
        email.setHtmlMsg(body);
        String[] receivers = configuration.getStringArray(CONFKEY_REPORTS_MAILER_SMTP_TO);
        for (String receiver : receivers) {
            email.addTo(receiver);
        }
        email.send();
        LOG.info("Report sent with email to " + email.getToAddresses().toString() + " (\"" + subject + "\")");
    } catch (EmailException e) {
        LOG.error(e.getMessage(), e);
    }
}
 
开发者ID:dma-ais,项目名称:AisAbnormal,代码行数:30,代码来源:ReportMailer.java

示例11: sendHtmlEmail

import org.apache.commons.mail.HtmlEmail; //导入方法依赖的package包/类
private void sendHtmlEmail() throws MangooMailerException {
    Config config = Application.getInstance(Config.class);
    try {
        HtmlEmail htmlEmail = new HtmlEmail();
        htmlEmail.setCharset(Default.ENCODING.toString());
        htmlEmail.setHostName(config.getSmtpHost());
        htmlEmail.setSmtpPort(config.getSmtpPort());
        htmlEmail.setAuthenticator(getDefaultAuthenticator());
        htmlEmail.setSSLOnConnect(config.isSmtpSSL());
        htmlEmail.setFrom(this.from);
        htmlEmail.setSubject(this.subject);
        htmlEmail.setHtmlMsg(render());
        
        for (String recipient : this.recipients) {
            htmlEmail.addTo(recipient);
        }
        
        for (String cc : this.ccRecipients) {
            htmlEmail.addCc(cc);
        }
        
        for (String bcc : this.bccRecipients) {
            htmlEmail.addBcc(bcc);
        }
        
        for (File file : this.files) {
            htmlEmail.attach(file);
        }
        
        htmlEmail.send();
    } catch (EmailException | MangooTemplateEngineException e) {
        throw new MangooMailerException(e);
    } 
}
 
开发者ID:svenkubiak,项目名称:mangooio,代码行数:35,代码来源:Mail.java

示例12: getHtmlEmail

import org.apache.commons.mail.HtmlEmail; //导入方法依赖的package包/类
public HtmlEmail getHtmlEmail() {
    HtmlEmail email = new HtmlEmail();

    email.setHostName(hostname);
    email.setSmtpPort(port);

    if (username != null && password != null && !username.isEmpty()) {
        email.setAuthenticator(new DefaultAuthenticator(username, password));
    }

    email.setSSLOnConnect(sslOnConnect);
    email.setStartTLSEnabled(startTslEnabled);
    email.setStartTLSRequired(requireTsl);

    return email;
}
 
开发者ID:UKHomeOffice,项目名称:email-api,代码行数:17,代码来源:HtmlEmailFactoryImpl.java

示例13: initializeMail

import org.apache.commons.mail.HtmlEmail; //导入方法依赖的package包/类
/**
 * Creates a {@link HtmlEmail} object configured as per the AuthMe config
 * with the given email address as recipient.
 *
 * @param emailAddress the email address the email is destined for
 * @return the created HtmlEmail object
 * @throws EmailException if the mail is invalid
 */
public HtmlEmail initializeMail(String emailAddress) throws EmailException {
    String senderMail = StringUtils.isEmpty(settings.getProperty(EmailSettings.MAIL_ADDRESS))
        ? settings.getProperty(EmailSettings.MAIL_ACCOUNT)
        : settings.getProperty(EmailSettings.MAIL_ADDRESS);

    String senderName = StringUtils.isEmpty(settings.getProperty(EmailSettings.MAIL_SENDER_NAME))
        ? senderMail
        : settings.getProperty(EmailSettings.MAIL_SENDER_NAME);
    String mailPassword = settings.getProperty(EmailSettings.MAIL_PASSWORD);
    int port = settings.getProperty(EmailSettings.SMTP_PORT);

    HtmlEmail email = new HtmlEmail();
    email.setCharset(EmailConstants.UTF_8);
    email.setSmtpPort(port);
    email.setHostName(settings.getProperty(EmailSettings.SMTP_HOST));
    email.addTo(emailAddress);
    email.setFrom(senderMail, senderName);
    email.setSubject(settings.getProperty(EmailSettings.RECOVERY_MAIL_SUBJECT));
    email.setAuthentication(settings.getProperty(EmailSettings.MAIL_ACCOUNT), mailPassword);
    if (settings.getProperty(PluginSettings.LOG_LEVEL).includes(LogLevel.DEBUG)) {
        email.setDebug(true);
    }

    setPropertiesForPort(email, port);
    return email;
}
 
开发者ID:AuthMe,项目名称:AuthMeReloaded,代码行数:35,代码来源:SendMailSsl.java

示例14: sendSupportEmail

import org.apache.commons.mail.HtmlEmail; //导入方法依赖的package包/类
public boolean sendSupportEmail() {
    try {
        String senderName = sender_name.getText();
        String senderEmail = sender_email.getText();
        String sendingTime = date_time.getText();
        String systemUser = system_user.getText();

        String message = messge_content.getText();

        if (message.isEmpty()) {
            JOptionPane.showMessageDialog(this, "You haven't entered your message. Please enter the message and try again.");
        }

        // Create the email message
        HtmlEmail email = new HtmlEmail();
        email.setHostName("host url");
        email.addTo("sender email", "Sender Name");
        email.setFrom("from email", "From Name");
        email.setAuthentication("username", "password");
        email.setSSLOnConnect(true);
        email.setStartTLSEnabled(true);
        email.addReplyTo("[email protected]", "Support Service - Company");
        email.setSmtpPort(465);

        email.setSubject("New Support Request from Application");

        // embed the image and get the content id
        URL url = getClass().getResource("/app/resources/shield_icon16x16.png");
        String cid = email.embed(url, "Application Logo");

        URL template = getClass().getResource("/app/support/email_template_20161101_isuru.emailtemplate");

        byte[] encoded = Files.readAllBytes(Paths.get(template.toURI()));
        String htmlMessage = new String(encoded, StandardCharsets.UTF_8);

        htmlMessage = htmlMessage.replace("_EP1_", "cid:" + cid);
        htmlMessage = htmlMessage.replace("_EP2_", systemUser);
        htmlMessage = htmlMessage.replace("_EP3_", senderName + "(" + senderEmail + ")");
        htmlMessage = htmlMessage.replace("_EP4_", sendingTime);
        htmlMessage = htmlMessage.replace("_EP5_", message.replaceAll("\\r?\\n", "<br />"));

        // set the html message
        email.setHtmlMsg(htmlMessage);

        String textMessage = "Application - Support Request\n"
                + "---------------------------------------------------------------------\n"
                + "New Support Request from P1\n"
                + "Sent by P2 on P3\n"
                + "---------------------------------------------------------------------\n"
                + "\n"
                + "Message: \nP4\n"
                + "\n"
                + "---------------------------------------------------------------------\n"
                + "This is an automatically generated email sent from Application.\n"
                + "\n"
                + "© All Rights Reserved - Management Development Co-operative Co. Ltd.";

        textMessage = textMessage.replace("P1", systemUser);
        textMessage = textMessage.replace("P2", senderName + "(" + senderEmail + ")");
        textMessage = textMessage.replace("P3", sendingTime);
        textMessage = textMessage.replace("P4", message);

        // set the alternative message
        email.setTextMsg(textMessage);

        // send the email
        email.send();
        return true;
    } catch (Exception e) {
        JOptionPane.showMessageDialog(this, "Cannot send email.\nError:" + e.getLocalizedMessage(), "Sending failure", JOptionPane.ERROR_MESSAGE);
        return false;
    }
}
 
开发者ID:isu3ru,项目名称:java-swing-template,代码行数:74,代码来源:Support.java

示例15: getPasswrod

import org.apache.commons.mail.HtmlEmail; //导入方法依赖的package包/类
/**
 * @Title: getpassword
 * @Description: TODO(会员忘记密码,通过邮箱获取密码)
 * @param @param member
 * @param @param session
 * @param @return设定文件
 * @return Object 返回类型
 * @throws
 * 
 */
@RequestMapping(value = "/getPasswrod.htm", method = RequestMethod.GET)
public Object getPasswrod(@Valid
String useremal, HttpServletRequest request, HttpSession session) {
    JqReturnJson returnResult = new JqReturnJson();// 构建返回结果,默认结果为false
    Member member = new Member();
    if (useremal == null) {
        returnResult.setMsg("邮箱不能为空");
        // 邮箱不存在,就返回这个消息给前台
        session.setAttribute("emailStatus", "false");
        return "retrievePassword/retrievePasswordEmail";
    }
    member = memberService.retrieveEmail(useremal);
    if (member == null) {
        returnResult.setMsg("邮箱不存在");
        // 邮箱不存在,就返回这个消息给前台
        session.setAttribute("emailStatus", "false");
        return "retrievePassword/retrievePasswordEmail";
    }
    returnResult.setSuccess(true);
    ModelAndView mav = new ModelAndView("retrievePassword/sendMail");
    // 创建一个临时ID
    String retrieveId = "" + Math.random() * Math.random();
    /**
     * 得到web系统url路径的方法
     * */
    // 得到web的url路径:http://localhost:8080/ssh1/
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
    // 邮件发送成功后,用户点在邮箱中点击这个链接回到设置新密码网站。
    String url = basePath + "mailBackPassword.htm?retrieveId=" + retrieveId;
    // 将验证邮箱链接后面的registerId存到session中
    session.setAttribute(retrieveId, retrieveId);
    session.setAttribute("userEmail", useremal);// 把用户邮箱保存起来
    // 把用户邮箱存起来
    // 设置session的有效时间,为10分钟,10分钟内没有点击链接的话,设置密码将失败
    session.setMaxInactiveInterval(600);
    // 基于org.apache.commons.mail,封装好的mail,发邮件流程比较简单,比原生态mail简单。
    HtmlEmail email = new HtmlEmail();
    email.setHostName("smtp.qq.com");// QQ郵箱服務器
    // email.setHostName("smtp.163.com");// 163郵箱服務器
    // email.setHostName("smtp.gmail.com");// gmail郵箱服務器
    email.setSmtpPort(465);// 设置端口号
    email.setAuthenticator(new DefaultAuthenticator("[email protected]", "zx5304960"));// 用[email protected]这个邮箱发送验证邮件的
    email.setTLS(true);// tls要设置为true,没有设置会报错。
    email.setSSL(true);// ssl要设置为true,没有设置会报错。
    try {
        email.setFrom("[email protected]", "冰川网贷管理员", "UTF-8");
        // email.setFrom("[email protected]", "[email protected]",
        // "UTF-8");
        // email.setFrom("[email protected]", "[email protected]", "UTF-8");
    } catch (EmailException e1) {
        e1.printStackTrace();
    }
    email.setCharset("UTF-8");// 没有设置会乱码。
    try {
        email.setSubject("冰川网贷密码找回");// 设置邮件名称
        email.setHtmlMsg("尊敬的会员:<font color='blue'>" + member.getMemberName() + "</font>,请点击<a href='" + url + "'>" + url + "</a>完成新密码设置!");// 设置邮件内容
        email.addTo(useremal);// 给会员发邮件
        email.send();// 邮件发送
    } catch (EmailException e) {
        throw new RuntimeException(e);
    }
    return mav;
}
 
开发者ID:GlacierSoft,项目名称:netloan-project,代码行数:75,代码来源:RegisterController.java


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