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


Java HtmlEmail.setAuthentication方法代码示例

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


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

示例1: sendEmail

import org.apache.commons.mail.HtmlEmail; //导入方法依赖的package包/类
private void sendEmail(String content) throws Exception {
	System.out.println("Send Email:");
	if (!Config.getBoolean("email.enabled")) {
		return;
	}
	
	HtmlEmail email = new HtmlEmail();
	for (String receipt : Config.getArrayProperty("report.email.recipients")) {
		email.addTo(receipt);
	}
	email.setFrom(Config.getProperty("report.email.from"));
	email.setSubject(Config.getProperty("report.email.subject"));
	email.setHtmlMsg(content);
	email.setHostName(Config.getProperty("report.email.host"));
	email.setAuthentication(Config.getProperty("report.email.username"), 
			Config.getProperty("report.email.password"));
	email.send();
}
 
开发者ID:21ca,项目名称:selenium-testng-template,代码行数:19,代码来源:SendEmailReporter.java

示例2: sendEmail

import org.apache.commons.mail.HtmlEmail; //导入方法依赖的package包/类
private void sendEmail() throws EmailException
{
	HtmlEmail email = new HtmlEmail();
	email.setHostName(smtpServer);
	if (smtpUser != null && smtpPassword != null) email.setAuthentication(smtpUser, smtpPassword);

	if (smtpSslPort != null)
	{
		email.setSSL(true);
		email.setSslSmtpPort(smtpSslPort);
	}

	Session session = email.getMailSession();
	Properties properties = session.getProperties();
	properties.setProperty("mail.smtp.connectiontimeout", "20000");
	properties.setProperty("mail.smtp.timeout", "20000");

	email.addTo(recipientEmailAddress, recipientEmailAddress);
	email.setFrom(smtpUser, smtpUser);

	email.setSubject(subject);
	email.setHtmlMsg(contents);
	email.setTextMsg(contents);
	email.send();
}
 
开发者ID:williamgrosset,项目名称:OSCAR-ConCert,代码行数:26,代码来源:Log4JGmailExecutorTask.java

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

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

示例5: sendMailByApache

import org.apache.commons.mail.HtmlEmail; //导入方法依赖的package包/类
public static void sendMailByApache(String to, String title, String content) {

        try {
            HtmlEmail email = new HtmlEmail();
            // 这里是发送服务器的名字
            email.setHostName(smtpHost);
            // 编码集的设置
            email.setTLS(true);
            email.setSSL(true);

            email.setCharset("utf-8");
            // 收件人的邮箱
            email.addTo(to);
            // 发送人的邮箱
            email.setFrom(fromEmail);
            // 如果需要认证信息的话,设置认证:用户名-密码。分别为发件人在邮件服务器上的注册名称和密码
            email.setAuthentication(username, password);
            email.setSubject(title);
            // 要发送的信息
            email.setMsg(content);
            // 发送
            email.send();
        } catch (EmailException e) {
            Log.i("EmailUtil", e.getMessage());
        }
    }
 
开发者ID:PureDark,项目名称:H-Viewer,代码行数:27,代码来源:EmailUtil.java

示例6: test

import org.apache.commons.mail.HtmlEmail; //导入方法依赖的package包/类
/**
 * send mail
 */
@Test
public void test() {
    try {
        HtmlEmail htmlEmail = new HtmlEmail();
        htmlEmail.setHostName("smtp.qq.com");
        htmlEmail.setFrom("[email protected]", "[email protected]");
        htmlEmail.addTo("[email protected]");
        htmlEmail.addCc("[email protected]", "[email protected]");
        htmlEmail.setAuthentication("[email protected]", "TaylorSwift");
        htmlEmail.setSubject("email example");
        htmlEmail.setHtmlMsg("test apache email");
        htmlEmail.setCharset("UTF-8");
        htmlEmail.buildMimeMessage();
        htmlEmail.sendMimeMessage();
    } catch (EmailException e) {
        System.out.println(e.getMessage());
    }
}
 
开发者ID:sunlin901203,项目名称:example-java,代码行数:22,代码来源:EmailExample.java

示例7: sendHtml

import org.apache.commons.mail.HtmlEmail; //导入方法依赖的package包/类
@Override
public boolean sendHtml(String to, String subject, String content) throws EmailException {
	HtmlEmail email = new HtmlEmail();
	email.setHostName(host);// 设置使用发电子邮件的邮件服务器
	email.addTo(to);
	email.setAuthentication(user, password);
	email.setFrom(user);
	email.setSubject(subject);
	email.setMsg(content);
	email.setSSLOnConnect(true);
	email.setSslSmtpPort("465"); // 若启用,设置smtp协议的SSL端口号
	email.send();
	return true;
}
 
开发者ID:tanhaichao,项目名称:leopard,代码行数:15,代码来源:MailClientImpl.java

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

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

示例10: enviaEmailFormatoHtml

import org.apache.commons.mail.HtmlEmail; //导入方法依赖的package包/类
/**
 * Envia email no formato HTML
 *
 * @param nomeRemetente
 * @param nomeDestinatario
 * @param emailRemetente
 * @param emailDestinatario
 * @param assunto
 * @param mensagem
 * @param anexo
 *
 * @throws EmailException
 * @throws MalformedURLException
 */
public void enviaEmailFormatoHtml(String nomeRementente, String emailRemetente,
        String nomeDestinatario, String emailDestinatario,
        String assunto, StringBuilder mensagem,
        String anexo) throws EmailException, MalformedURLException {

    HtmlEmail email = new HtmlEmail();

    // adiciona uma imagem ao corpo da mensagem e retorna seu id
    URL url = new URL(anexo); // URL do arquivo a ser anexado
    String cid = email.embed(url, "Anexos");

    // configura a mensagem para o formato HTML
    email.setHtmlMsg("<html>Anexos</html>");

    // configure uma mensagem alternativa caso o servidor não suporte HTML
    email.setTextMsg("Seu servidor de e-mail não suporta mensagem HTML");

    email.setHostName("smtp.hslife.com.br"); // o servidor SMTP para envio do e-mail
    email.addTo(emailDestinatario, nomeDestinatario); //destinatário
    email.setFrom(emailRemetente, nomeRementente); // remetente
    email.setSubject(assunto); // assunto do e-mail
    email.setMsg(mensagem.toString()); //conteudo do e-mail
    email.setAuthentication("[email protected]", "real123");
    //email.setSmtpPort(465);
    //email.setSSL(true);
    //email.setTLS(true);

    // envia email
    email.send();
}
 
开发者ID:herculeshssj,项目名称:imobiliariaweb,代码行数:45,代码来源:EmailService.java

示例11: sendEmail

import org.apache.commons.mail.HtmlEmail; //导入方法依赖的package包/类
/**
 * Simple method to send a single email using the EMailServerSettings.
 *
 * @param settings
 * @param fromAddress
 * @param firstAddress
 * @param object2
 * @param object
 * @param subject
 * @param body
 * @param attachedFiles
 * @param string
 * @throws EmailException
 */
public void sendEmail(final SMTPServerSetting settings, final String fromAddress, String bounceEmailAddress,
		final List<EmailTarget> targets, final String subject, final String body,
		final HashSet<? extends DataSource> attachedFiles) throws EmailException
{
	final HtmlEmail email = new HtmlEmail();

	email.setDebug(true);
	email.setHostName(settings.getSmtpFQDN());
	email.setSmtpPort(settings.getSmtpPort());
	email.setSSLCheckServerIdentity(false);
	if (settings.isAuthRequired())
	{
		email.setAuthentication(settings.getUsername(), settings.getPassword());
	}
	if (settings.getUseSSL())
	{
		email.setSslSmtpPort(settings.getSmtpPort().toString());
		email.setSSLOnConnect(true);
		email.setSSLCheckServerIdentity(false);
	}
	email.setFrom(fromAddress);
	email.setBounceAddress(bounceEmailAddress);

	for (final EmailTarget target : targets)
	{
		addEmailAddress(email, target.emailAddress, target.type);
	}

	email.setSubject(subject);
	email.setHtmlMsg(body);
	email.setTextMsg("Your email client does not support HTML messages");
	if (attachedFiles != null)
	{
		for (final DataSource attachedFile : attachedFiles)
		{
			email.attach(attachedFile, attachedFile.getName(), attachedFile.getContentType());
		}
	}

	email.send();

}
 
开发者ID:bsutton,项目名称:scoutmaster,代码行数:57,代码来源:SMTPSettingsDao.java

示例12: sendHtmlMail

import org.apache.commons.mail.HtmlEmail; //导入方法依赖的package包/类
@Override
public void sendHtmlMail(Email cerberusEmail) throws Exception {

    HtmlEmail email = new HtmlEmail();
    email.setSmtpPort(cerberusEmail.getSmtpPort());
    email.setHostName(cerberusEmail.getHost());
    email.setFrom(cerberusEmail.getFrom());
    email.setSubject(cerberusEmail.getSubject());
    email.setHtmlMsg(cerberusEmail.getBody());
    email.setTLS(cerberusEmail.isSetTls());
    email.setDebug(true);

    if (!StringUtils.isNullOrEmpty(cerberusEmail.getUserName()) || !StringUtils.isNullOrEmpty(cerberusEmail.getPassword())) {
        email.setAuthentication(cerberusEmail.getUserName(), cerberusEmail.getPassword());
    }

    String[] destinataire = cerberusEmail.getTo().split(";");
    for (int i = 0; i < destinataire.length; i++) {
        String name;
        String emailaddress;
        if (destinataire[i].contains("<")) {
            String[] destinatairedata = destinataire[i].split("<");
            name = destinatairedata[0].trim();
            emailaddress = destinatairedata[1].replace(">", "").trim();
        } else {
            name = "";
            emailaddress = destinataire[i];
        }
        email.addTo(emailaddress, name);
    }

    if (!StringUtil.isNullOrEmpty(cerberusEmail.getCc())) {
        String[] copy = cerberusEmail.getCc().split(";");

        for (int i = 0; i < copy.length; i++) {
            String namecc;
            String emailaddresscc;
            if (copy[i].contains("<")) {
                String[] copydata = copy[i].split("<");
                namecc = copydata[0].trim();
                emailaddresscc = copydata[1].replace(">", "").trim();
            } else {
                namecc = "";
                emailaddresscc = copy[i];
            }
            email.addCc(emailaddresscc, namecc);
        }
    }

    email.send();

}
 
开发者ID:cerberustesting,项目名称:cerberus-source,代码行数:53,代码来源:EmailService.java


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