Issue
We have a mailing feature in our Wicket 6 Web Application. Recently, I had to change the credentials of the mailing server to a new one. I tested it on my local system (OS Windows, Tomcat 7 web server) and it worked perfectly fine. The mail was send and I received it. When I applied the same credentials on our web server (OS: Debian) I get the following error message: 501 - Syntax error in parameters or arguments
I checked the mail address multiple times but everything seems to be fine. Thus, I am guessing that maybe the message is blocked somehow on the server either from the tomcat 7, the apache 2 or the hoster (although I called the hoster and they told me that their firewall is not blocking any outgoing signals). However, with the old credentials the mailing service is running perfectly fine. Thus not all outgoing signals are blocked.
I am not very experienced with such server configurations. Can anybody please give me a hint where I have to check the configuration. Thank you for your support.
EDIT
For sending the mail we are using the embedded javamail service of the spring framework. The code looks like this:
public class PrMailSendServiceImpl implements IPrMailSenderService{
private JavaMailSenderImpl javaMailSenderService;
private String defaultEmailFrom = "[email protected]";
private String defaultEmailTo;
public void sendEmail(String toEmail, String mailSubject, String mailContent) throws MessagingException {
MimeMessage msg = javaMailSenderService.createMimeMessage();
MimeMessageHelper mime = new MimeMessageHelper(msg, true, "UTF-8");
mime.setText(mailContent, true);
mime.setSubject(mailSubject);
mime.setTo(toEmail);
mime.setFrom(defaultEmailFrom);
javaMailSenderService.send(msg);
}
/*getter and setter*/
}
The described error occurs while the send method is executed.
The spring-context.xml file contains te following configurations:
<bean id="javaMailSenderService" class="org.springframework.mail.javamail.JavaMailSenderImpl">
<property name="host" value="mrvnet.kundenserver.de" />
<property name="port" value="25" />
<property name="username" value="[email protected]" />
<property name="password" value="myPassword" />
<property name="javaMailProperties">
<props>
<prop key="mail.smtp.auth">true</prop>
<prop key="mail.smtp.starttls.enable">true</prop>
</props>
</property>
</bean>
<bean id="mailSendService" class="de.virtualsolution.procon.service.impl.PrMailSendServiceImpl">
<property name="javaMailSenderService"><ref bean="javaMailSenderService" /></property>
<property name="defaultEmailFrom"><value>my@mailcom</value></property>
</bean>
Solution
I figured out the problem. I took the answer from https://community.hpe.com/t5/System-Administration/Error-sending-e-mails-from-Java-ehlo-problem/td-p/4145190
Simple Mail Transfer Protocol RFCs stipulate use of HELO and EHLO. Invalid usage of HELO/EHLO in the SMTP dialogue is your problem. Most Mail Transfer Agents (MTAs)perform DNS (A- and PTR- resource records) verification on the domain name given on the SMTP HELO and EHLO commands. This can violate RFC 2821, so email is usually not rejected by default. In other words, EHLO and HELO typically require FQDN. A client MUST issue HELO or EHLO before starting a mail transaction.
SOLUTION (see Unable to send email using javamail api in linux)
On our server we have several sub-domains. Thus, when calling InetAddress.getLocalHost().getHostName()
an exception was thrown. Therefore, to manually set the required host name for the HELO I added the line <prop key="mail.smtp.localhost">my.server.host.name</prop>
in the spring-context.xml
Now it looks like:
<bean id="javaMailSenderService" class="org.springframework.mail.javamail.JavaMailSenderImpl">
<property name="host" value="mrvnet.kundenserver.de" />
<property name="port" value="25" />
<property name="username" value="[email protected]" />
<property name="password" value="myPassword" />
<property name="javaMailProperties">
<props>
<prop key="mail.smtp.auth">true</prop>
<prop key="mail.smtp.starttls.enable">true</prop>
<prop key="mail.smtp.localhost">my.server.host.name</prop>
</props>
</property>
</bean>
<bean id="mailSendService" class="de.virtualsolution.procon.service.impl.PrMailSendServiceImpl">
<property name="javaMailSenderService"><ref bean="javaMailSenderService" /></property>
<property name="defaultEmailFrom"><value>my@mailcom</value></property>
</bean>
Answered By - Felix H