title: javamail - 504 5.5.2 : Helo command rejected: need fully-qualified hostname
body: <p>i will send mail via java mail in my webapp. i wrote a code and test it via gmail account and it works fine. then i replace my host smtp detail with gmail information and test it. oops it return my a following exception:</p>
  
  <pre><code>javax.mail.MessagingException: 504 5.5.2 &lt;rasta-PC&gt;: Helo command rejected: need fully-qualified hostname
  
      at com.sun.mail.smtp.SMTPTransport.issueCommand(SMTPTransport.java:2099)
      at com.sun.mail.smtp.SMTPTransport.helo(SMTPTransport.java:1490)
      at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:662)
      at javax.mail.Service.connect(Service.java:367)
      at javax.mail.Service.connect(Service.java:226)
      at javax.mail.Service.connect(Service.java:175)
      at javax.mail.Transport.send0(Transport.java:253)
      at javax.mail.Transport.send(Transport.java:124)
      at util.MailUtil.sendViaSSL(MailUtil.java:43)
      at control.member.AddMemberControl.add(AddMemberControl.java:107)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
      at java.lang.reflect.Method.invoke(Unknown Source)
      at org.apache.el.parser.AstValue.invoke(AstValue.java:278)
      at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:274)
      at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
      at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:87)
      at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
      at javax.faces.component.UICommand.broadcast(UICommand.java:315)
      at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
      at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)
      at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
      at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
      at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
      at javax.faces.webapp.FacesServlet.service(FacesServlet.java:646)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
      at org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:357)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
      at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
      at filter.CheckLoginFilter.doFilter(CheckLoginFilter.java:57)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
      at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
      at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
      at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
      at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
      at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
      at java.lang.Thread.run(Unknown Source)
  </code></pre>
  
  <p>you can see my code in the following:  </p>
  
  <pre><code>public static void sendViaSSL(final MailServerDetail msd,String to, String subject, String text){
  
      Properties props=new Properties();
      props.put("mail.smtp.host", "smtp.hostname");
      props.put("mail.smtp.socketFactory.port", "587");
      props.put("mail.smtp.socketFactory.class","javax.net.ssl.SSLSocketFactory");
      props.put("mail.smtp.auth", "true");
      props.put("mail.smtp.port", "587");
      props.put("mail.smtp.ssl", "true");                 
      props.put("mail.smtp.starttls.enable","true");
      props.put("mail.smtp.timeout", "5000");             
      props.put("mail.smtp.connectiontimeout", "5000"); 
      Session session=Session.getInstance(props, new Authenticator() {
          protected PasswordAuthentication getPasswordAuthentication() {
          return new PasswordAuthentication("My Mail Address", "Mail Password");
          }
      });
  
      MimeMessage message=new MimeMessage(session);
      try {
          message.setHeader("Content-Type", "text/plain; charset=UTF-8"); 
          message.setFrom(new InternetAddress("My Mail Address"));
          message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to));
          message.setSubject(subject,"UTF-8");
          message.setText(text, "UTF-8","html");
  
          Transport.send(message);
      } catch (AddressException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      } catch (MessagingException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
  }  
  </code></pre>
  
  <p>can you help me solve it? 
  thanks.</p>