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.Address;
|
||||||
import javax.mail.Message;
|
import javax.mail.Message;
|
||||||
import javax.mail.MessagingException;
|
|
||||||
import javax.mail.Session;
|
import javax.mail.Session;
|
||||||
import javax.mail.Transport;
|
import javax.mail.Transport;
|
||||||
import javax.mail.internet.AddressException;
|
import javax.mail.internet.AddressException;
|
||||||
|
@ -52,6 +51,7 @@ public class EmailNotification {
|
||||||
* @param recipient an email address
|
* @param recipient an email address
|
||||||
* @param subject the subject of your email
|
* @param subject the subject of your email
|
||||||
* @param body the body 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) {
|
public EmailNotification(String recipient, String subject, String body, HttpServletRequest httpServletRequest) {
|
||||||
String[] emailRecipients = new String[1];
|
String[] emailRecipients = new String[1];
|
||||||
|
@ -62,6 +62,7 @@ public class EmailNotification {
|
||||||
* @param recipients an array of email addresses
|
* @param recipients an array of email addresses
|
||||||
* @param subject the subject of your email
|
* @param subject the subject of your email
|
||||||
* @param body the body 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) {
|
public EmailNotification(String recipients[], String subject, String body, HttpServletRequest httpServletRequest) {
|
||||||
init(httpServletRequest, recipients, subject, body);
|
init(httpServletRequest, recipients, subject, body);
|
||||||
|
@ -71,6 +72,7 @@ public class EmailNotification {
|
||||||
* @param recipients a list of email addresses
|
* @param recipients a list of email addresses
|
||||||
* @param subject the subject of your email
|
* @param subject the subject of your email
|
||||||
* @param body the body 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) {
|
public EmailNotification(List<String> recipients, String subject, String body, HttpServletRequest httpServletRequest) {
|
||||||
init(httpServletRequest, recipients.toArray(new String[recipients.size()]), subject, body);
|
init(httpServletRequest, recipients.toArray(new String[recipients.size()]), subject, body);
|
||||||
|
@ -106,9 +108,16 @@ public class EmailNotification {
|
||||||
session.setDebug(true);
|
session.setDebug(true);
|
||||||
Message mimeMessage = new MimeMessage(session);
|
Message mimeMessage = new MimeMessage(session);
|
||||||
try {
|
try {
|
||||||
|
String emailSender = "";
|
||||||
|
String siteName = "";
|
||||||
// EMAIL SENDER
|
// EMAIL SENDER
|
||||||
String emailSender = PortalContext.getConfiguration().getSenderEmail(request);
|
if (request != null) {
|
||||||
String siteName = PortalContext.getConfiguration().getGatewayName(request);
|
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);
|
Address from = new InternetAddress(emailSender, siteName);
|
||||||
mimeMessage.setHeader("Content-Type", "text/html; charset=UTF-8");
|
mimeMessage.setHeader("Content-Type", "text/html; charset=UTF-8");
|
||||||
mimeMessage.setFrom(from);
|
mimeMessage.setFrom(from);
|
||||||
|
|
Loading…
Reference in New Issue