title: Problem configuring Spring's MailSender for our SMTP-server (but GMail works)
body: <p>I have some problems sending mails through SMTP using Spring's <a href="http://static.springframework.org/spring/docs/1.2.x/api/org/springframework/mail/MailSender.html" rel="nofollow noreferrer">MailSender</a> interface and the concrete implementation <a href="http://static.springframework.org/spring/docs/1.2.x/api/org/springframework/mail/javamail/JavaMailSenderImpl.html" rel="nofollow noreferrer">JavaMailSenderImpl</a>. I'm able to send mail through GMail, but not through our company SMTP-server (<a href="http://www.postfix.org/" rel="nofollow noreferrer">Postfix</a>).</p>
  
  <h2>Correct configurations</h2>
  
  <p>To see that I have the correct configuration I used the excellent mail sender <a href="http://www.google.com/search?q=ssmtp" rel="nofollow noreferrer">ssmtp</a>. It's a simple utility (which is able to emulate Sendmail) and is used solely for sending mail through SMTP.</p>
  
  <p>Below are the two commands I used to send mail. The first one is for GMail and the second one for our company SMTP-server. Both mails arrived as they should and thus the configuration files that follow are correct.</p>
  
  <pre><code>$ ssmtp -C gmail-smtp.conf john.doe@gmail.com &lt; gmail-message.txt 
  $ ssmtp -C other-smtp.conf john.doe@thecompany.net &lt; other-message.txt
  </code></pre>
  
  <p>The contents of the ssmtp configuration files and the message files are listed below. How the configuration file is structured can be seen at: <a href="http://linux.die.net/man/5/ssmtp.conf" rel="nofollow noreferrer">http://linux.die.net/man/5/ssmtp.conf</a>:</p>
  
  <p><em>gmail-message.txt:</em></p>
  
  <pre><code>To: john.doe@gmail.com
  From: john.doe@gmail.com
  Subject: Sent using the SMTP-server of GMail
  
  Some content.
  </code></pre>
  
  <p><em>gmail-smtp.conf:</em></p>
  
  <pre><code>mailhub=smtp.gmail.com:587
  UseSTARTTLS=yes
  AuthUser=john.doe@gmail.com
  AuthPass=john_password
  </code></pre>
  
  <p><em>other-message.txt:</em></p>
  
  <pre><code>To: john.doe@thecompany.net
  From: john.doe@thecompany.net
  Subject: Sent using the SMTP-server of TheCompany
  
  Some content.
  </code></pre>
  
  <p><em>other-smtp.conf:</em></p>
  
  <pre><code># No username or password = no authentication
  hostname=thecompany.net
  mailhub=mail.thecompany.net:25
  </code></pre>
  
  <h2>MailSender configuration which works against GMail</h2>
  
  <p>I'm sucessful in sending mail through GMail using this Spring MailSender configuration:</p>
  
  <pre><code>...
  &lt;bean id="mailSender" class ="org.springframework.mail.javamail.JavaMailSenderImpl" &gt;
      &lt;property name="host" value="smtp.gmail.com" /&gt;
      &lt;property name="port" value="587" /&gt;
      &lt;property name="username" value="john.doe@gmail.com" /&gt;
      &lt;property name="password" value="john_password" /&gt;
      &lt;property name="javaMailProperties"&gt;
      &lt;props&gt;
          &lt;prop key="mail.smtp.starttls.enable"&gt;true&lt;/prop&gt;
      &lt;/props&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  ...
  </code></pre>
  
  <h2>The problem (sending through the company SMTP-server)</h2>
  
  <p>With this MailSender configuration:</p>
  
  <pre><code>...
  &lt;bean id="mailSender" class ="org.springframework.mail.javamail.JavaMailSenderImpl" &gt;
      &lt;property name="host" value="mail.thecompany.net" /&gt;
      &lt;property name="port" value="25" /&gt;
  &lt;/bean&gt;
  ...
  </code></pre>
  
  <p>I get this exception:</p>
  
  <pre><code>org.springframework.mail.MailSendException; nested exceptions (1) are:
  Failed message 1: javax.mail.SendFailedException: Invalid Addresses;
  nested exception is:
  com.sun.mail.smtp.SMTPAddressFailedException: 504 5.5.2 &lt;rat&gt;: Helo command rejected: need fully-qualified hostname
  
  at org.springframework.mail.javamail.JavaMailSenderImpl.doSend(JavaMailSenderImpl.java:422)
  at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:308)
  at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:297)
  ... (The rest are methods I've created, which are irrelevant)    
  </code></pre>
  
  <p>I <strong>also</strong> get <em>504 5.5.2 : Helo command rejected: need fully-qualified hostname</em> if I remove <em>hostname=thecompany.net</em> from <em>other-smtp.conf</em> using <strong>ssmtp</strong>. I guess I have to provide the hostname somehow. My computers name is <em>rat</em> but it seems like it wants <em>thecompany.net</em>.</p>
  
  <p>Any and all help appreciated!</p>