本文整理汇总了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();
}
示例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.");
}
示例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.");
}
示例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;
}
}
示例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();
}
示例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 + "\">");
}