title: Java Mail won't work remotely
body: <p>I've made a Java Mail Servlet to obviously send emails. It works perfectly fine on the production server but when I try and run it on my own home server I get this following error message</p>
  
  <p>javax.mail.SendFailedException: Invalid Addresses;</p>
  
  <p>javax.servlet.ServletException: javax.mail.SendFailedException: Invalid Addresses;
    nested exception is:
      com.sun.mail.smtp.SMTPAddressFailedException: 554 5.7.1 &lt;<strong><em>*</em></strong>@googlemail.com>: Relay access denied</p>
  
  <pre><code>evo.net.Mail.service(Mail.java:60)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
  org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52
  </code></pre>
  
  <p>I changed the hostname variable from localhost to the server's IP in the servlet and it didnt make a difference.</p>
  
  <p>My code:</p>
  
  <pre><code>package evo.net;
  import java.util.*;
  
  import javax.mail.*;
  import javax.mail.Session;
  import javax.mail.internet.*;
  import javax.activation.*;
  
  import java.io.IOException;
  import java.io.PrintWriter;
  
   import javax.servlet.ServletException;
   import javax.servlet.annotation.WebServlet;
   import javax.servlet.http.HttpServlet;
   import javax.servlet.http.HttpServletRequest;
   import javax.servlet.http.HttpServletResponse;
  
   @WebServlet("/Mail")
   public class Mail extends HttpServlet {
  private static final long serialVersionUID = 1L;
  
   public Mail() {
      super();
   }
  
  protected void service(HttpServletRequest request, HttpServletResponse response)            throws ServletException, IOException {
  
      PrintWriter out = response.getWriter();
  
      String to = "********";
      String from = "*******@codeprojects.co.uk";
      String host = "codeprojects.co.uk";
  
      Properties props = System.getProperties();
  
      props.put("mail.smtp.host", host);
      props.put("mail.smtp.auth", "true");
  
      Session session = Session.getDefaultInstance(props, new Authenticator() {
              protected PasswordAuthentication getPasswordAuthentication() {
                  return new PasswordAuthentication("root", "*****");
              }
        });
  
      try {
          Transport trans = session.getTransport("smtp");
          trans.connect("root", "******");
  
          MimeMessage message = new MimeMessage(session);
          message.setFrom(new InternetAddress(from));
          message.addRecipient(Message.RecipientType.TO, new             InternetAddress(to));
  
          message.setSubject("The subject");
          message.setText("Hello World");
  
          trans.sendMessage(message, message.getAllRecipients());;
          out.println("Test");
  
      } catch(MessagingException mex) {
          throw new ServletException(mex);
      }
  }
    }
  </code></pre>