本文整理汇总了Java中org.apache.commons.mail.HtmlEmail.setTextMsg方法的典型用法代码示例。如果您正苦于以下问题:Java HtmlEmail.setTextMsg方法的具体用法?Java HtmlEmail.setTextMsg怎么用?Java HtmlEmail.setTextMsg使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.mail.HtmlEmail
的用法示例。
在下文中一共展示了HtmlEmail.setTextMsg方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.apache.commons.mail.HtmlEmail; //导入方法依赖的package包/类
/**
* This main method is useful when debugging smtp configuration problems.
*/
public static void main(String... argv) throws EmailException
{
// gmail : smtp.gmail.com:465
String fromEmailAddress=argv[0];
String toEmailAddress=argv[1];
String smtpServer=argv[2];
String smtpPort=(argv.length>3?argv[3]:null);
String smtpUser=(argv.length>4?argv[4]:null);
String smtpPassword=(argv.length>5?argv[4]:null);
String connectionSecurity=(argv.length>6?argv[5]:null);
HtmlEmail htmlEmail=EmailUtilsOld.getHtmlEmail(smtpServer, smtpPort, smtpUser, smtpPassword, connectionSecurity);
htmlEmail.addTo(toEmailAddress, toEmailAddress);
htmlEmail.setFrom(fromEmailAddress, fromEmailAddress);
htmlEmail.setSubject("test subject");
htmlEmail.setTextMsg("test contents "+(new java.util.Date()));
htmlEmail.send();
}
示例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();
}
示例3: 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();
}
示例4: sendHtmlAndTextEmail
import org.apache.commons.mail.HtmlEmail; //导入方法依赖的package包/类
@Override
public void sendHtmlAndTextEmail(String to, String subject, String htmlBody, String textBody) throws ServiceException {
HtmlEmail email = new HtmlEmail();
try {
setupEmail(email);
validateAddress(to);
email.addTo(to);
email.setSubject(subject);
email.setHtmlMsg(htmlBody);
email.setTextMsg(textBody);
email.send();
} catch (EmailException e) {
log.error("ZZZ.EmailException. To: " + to + " Subject: " + subject, e);
throw new ServiceException("Unable to send email.", e);
}
}
示例5: main
import org.apache.commons.mail.HtmlEmail; //导入方法依赖的package包/类
/**
* This main method is useful when debugging smtp configuration problems.
*/
public static void main(String... argv) throws EmailException
{
// gmail : smtp.gmail.com:465
String fromEmailAddress=argv[0];
String toEmailAddress=argv[1];
String smtpServer=argv[2];
String smtpPort=(argv.length>3?argv[3]:null);
String smtpUser=(argv.length>4?argv[4]:null);
String smtpPassword=(argv.length>5?argv[4]:null);
String connectionSecurity=(argv.length>6?argv[5]:null);
HtmlEmail htmlEmail=EmailUtils.getHtmlEmail(smtpServer, smtpPort, smtpUser, smtpPassword, connectionSecurity);
htmlEmail.addTo(toEmailAddress, toEmailAddress);
htmlEmail.setFrom(fromEmailAddress, fromEmailAddress);
htmlEmail.setSubject("test subject");
htmlEmail.setTextMsg("test contents "+(new java.util.Date()));
htmlEmail.send();
}
示例6: sendHtmlEmail
import org.apache.commons.mail.HtmlEmail; //导入方法依赖的package包/类
public static void sendHtmlEmail(String to, String subject, String template, Map<String, Object> variables) {
try {
final HtmlEmail email = new HtmlEmail();
setupEmail(email, to, subject, template, variables);
email.setHtmlMsg(EmailUtil.getHtmlBody(template, variables));
email.setTextMsg(EmailUtil.getTextBody(template, variables));
email.setSocketConnectionTimeout(Configuration.getSmtpConnectTimeout());
email.send();
} catch (Exception e) {
LOGGER.error("Error sending HTML email", e);
}
}
示例7: 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();
}
示例8: sendEmail
import org.apache.commons.mail.HtmlEmail; //导入方法依赖的package包/类
/**
* This is a convenience method for sending and email to 1 recipient using the configuration file settings.
* @throws EmailException
*/
public static void sendEmail(String toEmailAddress, String toName, String fromEmailAddress, String fromName, String subject, String textContents, String htmlContents) throws EmailException
{
HtmlEmail htmlEmail = getHtmlEmail();
htmlEmail.addTo(toEmailAddress, toName);
htmlEmail.setFrom(fromEmailAddress, fromName);
htmlEmail.setSubject(subject);
if (textContents != null) htmlEmail.setTextMsg(textContents);
if (htmlContents != null) htmlEmail.setHtmlMsg(htmlContents);
//htmlEmail.getMailSession().setDebug(true);
htmlEmail.send();
}
示例9: onMessage
import org.apache.commons.mail.HtmlEmail; //导入方法依赖的package包/类
/**
* Sends out an email
* @param message - message to be sent
*/
public void onMessage(Message message) {
try {
EmailRequest emailRequest = (EmailRequest)((ObjectMessage)message).getObject();
Query query = entityManager.createQuery("select e from Email e where e.action = ?1");
query.setParameter(1,emailRequest.getAction());
List results = query.getResultList();
if(results.size() != 1) {
logger.severe("A total of " + results.size() + " email templates were returned for action " +
emailRequest.getAction());
return;
}
System.out.println("--> Sending email.");
Email emailInfo = (Email)results.get(0);
logger.info("Speaker Directory: " + attachmentDirectory);
HtmlEmail email = new HtmlEmail();
email.setMailSession(mailSession);
email.setTextMsg("Hello World!");
// email.setSubject(template.getSubject());
email.addTo("[email protected]");
email.setFrom("[email protected]");
// email.send();
/* emailTemplate.process(emailRecipient.getReplacementTokens());
for (Map.Entry<String,File> entry : emailTemplate.getCidMappings().entrySet()) {
email.embed(entry.getValue(),entry.getKey());
}
email.setHtmlMsg(emailTemplate.getPatchedEmail());
*/
} catch(Throwable t) {
t.printStackTrace();
//context.setRollbackOnly();
}
}
示例10: build
import org.apache.commons.mail.HtmlEmail; //导入方法依赖的package包/类
public HtmlEmail build(final TemplatedEmail templatedEmail)
throws EmailException, TemplatePopulatorParsingException, TemplatePopulatorIOException,
InternetAddressParsingException {
HtmlEmail email = htmlEmailFactory.getHtmlEmail();
final Collection<InternetAddress> recipients =
addressParser.getInternetAddresses(templatedEmail.getRecipients());
email.setTo(recipients);
try {
email.setFrom(templatedEmail.getSender());
} catch (EmailException e) {
throw new InternetAddressParsingException(e);
}
email.setSubject(templatedEmail.getSubject());
String htmlProcessedTemplate = templateEngine
.populateTemplate(templatedEmail.getHtmlTemplate(), templatedEmail.getVariables());
email.setHtmlMsg(htmlProcessedTemplate);
final String txtProcessedTemplate = templateEngine
.populateTemplate(templatedEmail.getTextTemplate(), templatedEmail.getVariables());
email.setTextMsg(txtProcessedTemplate);
return email;
}
示例11: sendHtmlEmail
import org.apache.commons.mail.HtmlEmail; //导入方法依赖的package包/类
/**
* Test sending an {@link HtmlEmail}.
*/
@Test
public void sendHtmlEmail() throws Exception {
assertThat(this.sslMailServer.getReceivedMessages().length, is(0));
HtmlEmail email = new HtmlEmail();
email.setFrom("[email protected]");
email.setSubject("subject");
email.setHtmlMsg("<h1>Hi</h1>\nHope you're doing well.");
email.setTextMsg("Hi! Your mail client doesn't seem to support HTML.");
email.addTo("[email protected]");
email.setSentDate(UtcTime.now().toDate());
SmtpSender sender = new SmtpSender(email, new SmtpClientConfig("localhost", SMTP_SSL_PORT,
new SmtpClientAuthentication(USERNAME, PASSWORD), true));
sender.call();
// check mailbox after sending
MimeMessage[] receivedMessages = this.sslMailServer.getReceivedMessages();
assertThat(receivedMessages.length, is(1));
assertThat(receivedMessages[0].getSubject(), is("subject"));
assertThat(receivedMessages[0].getSentDate(), is(FrozenTime.now().toDate()));
MimeMessage message = receivedMessages[0];
Object content = message.getContent();
assertThat(content, instanceOf(MimeMultipart.class));
MimeMultipart mimeContent = (MimeMultipart) content;
Object firstPart = mimeContent.getBodyPart(0).getContent();
Object secondPart = mimeContent.getBodyPart(1).getContent();
assertThat(firstPart, is("Hi! Your mail client doesn't seem to support HTML."));
assertThat(secondPart, is("<h1>Hi</h1>\r\nHope you're doing well."));
}
示例12: sendEmail
import org.apache.commons.mail.HtmlEmail; //导入方法依赖的package包/类
/**
* This is a convenience method for sending and email to 1 recipient using the configuration file settings.
* @throws EmailException
*/
public static void sendEmail(String toEmailAddress, String toName, String fromEmailAddress, String fromName, String subject, String textContents, String htmlContents) throws EmailException
{
HtmlEmail htmlEmail = getHtmlEmail();
htmlEmail.addTo(toEmailAddress, toName);
htmlEmail.setFrom(fromEmailAddress, fromName);
htmlEmail.setSubject(subject);
if (textContents != null) htmlEmail.setTextMsg(textContents);
if (htmlContents != null) htmlEmail.setHtmlMsg(htmlContents);
htmlEmail.send();
}
示例13: 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;
}
}
示例14: createHtmlEmail
import org.apache.commons.mail.HtmlEmail; //导入方法依赖的package包/类
protected HtmlEmail createHtmlEmail(String text, String html) {
HtmlEmail email = new HtmlEmail();
try {
email.setHtmlMsg(html);
if (text != null) { // for email clients that don't support html
email.setTextMsg(text);
}
return email;
} catch (EmailException e) {
throw new FlowableException("Could not create HTML email", e);
}
}
示例15: createHtmlEmail
import org.apache.commons.mail.HtmlEmail; //导入方法依赖的package包/类
protected HtmlEmail createHtmlEmail(String text, String html) {
HtmlEmail email = new HtmlEmail();
try {
email.setHtmlMsg(html);
if (text != null) { // for email clients that don't support html
email.setTextMsg(text);
}
return email;
} catch (EmailException e) {
throw new ActivitiException("Could not create HTML email", e);
}
}