Merge pull request #41 from vivo-project/feature/1230

[VIVO-1230] Make contact form compatible with SMTP relays
This commit is contained in:
grahamtriggs 2016-06-02 15:00:44 +01:00
commit b0d0925101

View file

@ -12,6 +12,7 @@ import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import javax.mail.Address;
import javax.mail.Message; import javax.mail.Message;
import javax.mail.MessagingException; import javax.mail.MessagingException;
import javax.mail.SendFailedException; import javax.mail.SendFailedException;
@ -256,13 +257,13 @@ public class ContactMailController extends FreemarkerHttpServlet {
MimeMessage msg = new MimeMessage( s ); MimeMessage msg = new MimeMessage( s );
//System.out.println("trying to send message from servlet"); //System.out.println("trying to send message from servlet");
// Set the from address // Set the reply address
try { try {
msg.setFrom( new InternetAddress( webuseremail, webusername )); msg.setReplyTo( new Address[] { new InternetAddress( webuseremail, webusername ) } );
} catch (UnsupportedEncodingException e) { } catch (UnsupportedEncodingException e) {
log.error("Can't set message sender with personal name " + webusername + log.error("Can't set message reply with personal name " + webusername +
" due to UnsupportedEncodingException"); " due to UnsupportedEncodingException");
msg.setFrom( new InternetAddress( webuseremail ) ); // msg.setFrom( new InternetAddress( webuseremail ) );
} }
// Set the recipient address // Set the recipient address
@ -272,6 +273,13 @@ public class ContactMailController extends FreemarkerHttpServlet {
} }
msg.setRecipients( Message.RecipientType.TO, address ); msg.setRecipients( Message.RecipientType.TO, address );
// Set the from address
if (address != null && address.length > 0) {
msg.setFrom(address[0]);
} else {
msg.setFrom( new InternetAddress( webuseremail ) );
}
// Set the subject and text // Set the subject and text
msg.setSubject( deliveryfrom ); msg.setSubject( deliveryfrom );