【发布时间】:2016-08-15 13:58:57
【问题描述】:
我有一个处理用户注册的 servlet。此 servlet 还会向用户发送一封激活电子邮件。我已经在另一个类中实现了邮件发送,但这里是处理向用户发送邮件的函数:
if(localEjb.createUser(usr) != null)
{
boolean status = true;
EmailSetting emailSetting = localEjb.fetchSetting();
if(emailSetting != null)
{
Mail mail = new Mail();
String message = "Dear " + lastName + " , " +
"Your account has been created on Eventry. " +
"Please click this link '" + emailSetting.getBaseURL() + "activate?" + securityCode + "' to complete the activation process";
status = mail.send(emailSetting, emailSetting.getRecipient(), email, Message.EVENTRY_ACCOUNT_ACTIVATION_INSTRUCTIONS, message, null, null);
}
/*this user has been successfully created on the portal*/
this.respond(response, status, status ? Message.activation_mail_sent : Message.activation_mail_failed,null);
}
else
{
// a technical error occureed, we couldn't create the user (Should never happen)
this.respond(response, true, Message.registration_failed + Message.technical_fault, null);
}
现在,如您所见,我已经以一种非常简单的方式编写了要发送的消息,并且可以正常工作。但我现在真正需要的是拥有一个包含 CSS 和 HTML 的自定义电子邮件。我已经有了这个,但我不知道如何将它插入到 servlet 中。或者如果我可以使用JSP,我应该怎么做?
谢谢。
【问题讨论】:
-
Google for
java send html email with images,确实有很多的示例和教程。 -
感谢您的回答,但挑战不在于将 HTML 放入消息中,而在于 CSS 是问题所在。谢谢。 P.s 我认为在任何人对我的问题投反对票之前,他们至少应该就我能做什么提出建议。
-
嗯,此类搜索的大部分结果不仅讨论如何发送 HTML 电子邮件,还讨论如何将其他对象(图像、CSS 等)嵌入此类 HTML。
标签: java html jsp email servlets