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


Java HtmlEmail.embed方法代码示例

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


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

示例1: simple

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

	new ProxyInitializable().initialize();

	HtmlEmail email = new HtmlEmail();
	email.setHostName("mail.myserver.com");
	email.addTo("[email protected]", "John Doe");
	// email.setFrom("[email protected]", "Me");
	email.setSubject("Test email with inline image");

	// embed the image and get the content id
	// URL url = new URL("https://i.stack.imgur.com/r7Nij.jpg?s=32&g=1");
	String cid = email.embed(new File("123.jpg"));

	// set the html message
	email.setHtmlMsg("<html>The apache logo - <img src=\"cid:" + cid + "\"></html>");

	// set the alternative message
	email.setTextMsg("Your email client does not support HTML messages");

	MimeMessage mimeMessage = email.getMimeMessage();
	System.out.println(mimeMessage);

	System.out.println(email.sendMimeMessage());
	// send the email
	email.send();
}
 
开发者ID:callakrsos,项目名称:Gargoyle,代码行数:29,代码来源:MimeConverter.java

示例2: main

import org.apache.commons.mail.HtmlEmail; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    HtmlEmail email = new HtmlEmail();
    for (String recipient : RECIPIENTS) {
        email.addTo(recipient);
    }
    email.setFrom("[email protected]", "Elastisys Testing");
    email.setSubject("Test mail");
    // embed a remote image and get the content id
    String cid = email.embed(new File("src/test/resources/img/elastisys-logo.png"), "image");
    email.setHtmlMsg("<html><img height=200 src=\"cid:" + cid + "\"/><h1>Congratulations</h1>" + "\n"
            + "You are our one millionth customer!</html>");

    SmtpSender requester = new SmtpSender(email,
            new SmtpClientConfig(MAIL_SERVER, MAIL_PORT, AUTH, USE_SSL, 5000, 5000));

    System.out.println("sending email ...");
    requester.call();
    System.out.println("done.");
}
 
开发者ID:elastisys,项目名称:scale.commons,代码行数:20,代码来源:HtmlWithEmbeddedRemoteImageSmtpSenderLab.java

示例3: main

import org.apache.commons.mail.HtmlEmail; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    HtmlEmail email = new HtmlEmail();
    for (String recipient : RECIPIENTS) {
        email.addTo(recipient);
    }
    email.setFrom("[email protected]", "Elastisys Testing");
    email.setSubject("Test mail");
    // embed a remote image and get the content id
    URL url = new URL("https://upload.wikimedia.org/wikipedia/commons/f/f4/Alfred_Nobel.png");
    String cid = email.embed(url, "image");
    email.setHtmlMsg("<html><img src=\"cid:" + cid + "\"/><h1>Congratulations</h1>" + "\n"
            + "You have just won the nobel prize!</html>");

    SmtpSender requester = new SmtpSender(email,
            new SmtpClientConfig(MAIL_SERVER, MAIL_PORT, AUTH, USE_SSL, 5000, 5000));

    System.out.println("sending email ...");
    requester.call();
    System.out.println("done.");
}
 
开发者ID:elastisys,项目名称:scale.commons,代码行数:21,代码来源:HtmlWithEmbeddedLocalImageSmtpSenderLab.java

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

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

示例6: embedImageIntoEmailContent

import org.apache.commons.mail.HtmlEmail; //导入方法依赖的package包/类
private static String embedImageIntoEmailContent(File image, HtmlEmail email, String content)
    throws EmailException {
    DataSource source = new FileDataSource(image);
    String tag = email.embed(source, image.getName());
    return content.replace("<image />", "<img src=\"cid:" + tag + "\">");
}
 
开发者ID:AuthMe,项目名称:AuthMeReloaded,代码行数:7,代码来源:EmailService.java


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