updated EmailNotification class to allow sending with default email sender if no httpservler request is available
git-svn-id: https://svn.research-infrastructures.eu/d4science/gcube/trunk/portal/portal-manager@129918 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
5b5f785b4b
commit
ae24cd0d7d
|
@ -7,7 +7,6 @@ import java.util.Properties;
|
|||
|
||||
import javax.mail.Address;
|
||||
import javax.mail.Message;
|
||||
import javax.mail.MessagingException;
|
||||
import javax.mail.Session;
|
||||
import javax.mail.Transport;
|
||||
import javax.mail.internet.AddressException;
|
||||
|
@ -52,6 +51,7 @@ public class EmailNotification {
|
|||
* @param recipient an email address
|
||||
* @param subject the subject of your email
|
||||
* @param body the body of your email
|
||||
* @param httpServletRequest the httpServletRequest object if you have it, null otherwise (but the default sender will be applied in this case)
|
||||
*/
|
||||
public EmailNotification(String recipient, String subject, String body, HttpServletRequest httpServletRequest) {
|
||||
String[] emailRecipients = new String[1];
|
||||
|
@ -62,6 +62,7 @@ public class EmailNotification {
|
|||
* @param recipients an array of email addresses
|
||||
* @param subject the subject of your email
|
||||
* @param body the body of your email
|
||||
* @param httpServletRequest the httpServletRequest object if you have it, null otherwise (but the default sender will be applied in this case)
|
||||
*/
|
||||
public EmailNotification(String recipients[], String subject, String body, HttpServletRequest httpServletRequest) {
|
||||
init(httpServletRequest, recipients, subject, body);
|
||||
|
@ -71,6 +72,7 @@ public class EmailNotification {
|
|||
* @param recipients a list of email addresses
|
||||
* @param subject the subject of your email
|
||||
* @param body the body of your email
|
||||
* @param httpServletRequest the httpServletRequest object if you have it, null otherwise (but the default sender will be applied in this case)
|
||||
*/
|
||||
public EmailNotification(List<String> recipients, String subject, String body, HttpServletRequest httpServletRequest) {
|
||||
init(httpServletRequest, recipients.toArray(new String[recipients.size()]), subject, body);
|
||||
|
@ -106,9 +108,16 @@ public class EmailNotification {
|
|||
session.setDebug(true);
|
||||
Message mimeMessage = new MimeMessage(session);
|
||||
try {
|
||||
String emailSender = "";
|
||||
String siteName = "";
|
||||
// EMAIL SENDER
|
||||
String emailSender = PortalContext.getConfiguration().getSenderEmail(request);
|
||||
String siteName = PortalContext.getConfiguration().getGatewayName(request);
|
||||
if (request != null) {
|
||||
emailSender = PortalContext.getConfiguration().getSenderEmail(request);
|
||||
siteName = PortalContext.getConfiguration().getGatewayName(request);
|
||||
} else {
|
||||
emailSender = PortalContext.getConfiguration().getSenderEmail();
|
||||
siteName = PortalContext.getConfiguration().getGatewayName();
|
||||
}
|
||||
Address from = new InternetAddress(emailSender, siteName);
|
||||
mimeMessage.setHeader("Content-Type", "text/html; charset=UTF-8");
|
||||
mimeMessage.setFrom(from);
|
||||
|
|
Loading…
Reference in New Issue