title: Is it possible to send mail with Javamail without authentication?
body: <p>I've been copying this code
  <a href="http://www.tutorialspoint.com/java/java_sending_email.htm" rel="nofollow">http://www.tutorialspoint.com/java/java_sending_email.htm</a></p>
  
  <p>and I get the error</p>
  
  <pre><code>javax.mail.MessagingException: Could not connect to SMTP host: localhost, port: 465;
  nested exception is:
  java.net.SocketException: Connection reset
  at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1963)
  at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:654)
  at javax.mail.Service.connect(Service.java:345)
  at javax.mail.Service.connect(Service.java:226)
  at javax.mail.Service.connect(Service.java:175)
  at racetiming.MailSender.send(MailSender.java:68)
  </code></pre>
  
  <p>All the solutions I'm looking up are using authentication to log in to a mail server but I'm trying to do it without a login. Is this not possible? Seems like the tutorials are trying to do it without credentials.</p>
  
  <p>Here's the entirety of my code.</p>
  
  <pre><code>public class MailSender
  {
  public static void send(Racer r, String filename){
    // Recipient's email ID needs to be mentioned.
    String to = r.getEmail();
  
    // Sender's email ID needs to be mentioned
    String from = "donotreplyRFID@gmail.com";
  
    // Assuming you are sending email from localhost
    String host = "localhost";
  
    // Get system properties
    Properties properties = System.getProperties();
  
    // Setup mail server
    properties.setProperty("mail.smtp.host", host);
    properties.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
  
    // Get the default Session object.
    Session session = Session.getDefaultInstance(properties);
  
    try{
       // Create a default MimeMessage object.
       MimeMessage message = new MimeMessage(session);
  
       // Set From: header field of the header.
       message.setFrom(new InternetAddress(from));
  
       // Set To: header field of the header.
       message.addRecipient(Message.RecipientType.TO,
                                new InternetAddress(to));
  
       // Set Subject: header field
       message.setSubject("Report for " + r.getName());
  
       // Create the message part 
       BodyPart messageBodyPart = new MimeBodyPart();
  
       // Fill the message
       messageBodyPart.setText("See attachment");
  
       // Create a multipart message
       Multipart multipart = new MimeMultipart();
  
       // Set text message part
       multipart.addBodyPart(messageBodyPart);
  
       // Part two is attachment
       messageBodyPart = new MimeBodyPart();
       DataSource source = new FileDataSource(filename);
       messageBodyPart.setDataHandler(new DataHandler(source));
       messageBodyPart.setFileName(filename);
       multipart.addBodyPart(messageBodyPart);
  
       // Send the complete message parts
       message.setContent(multipart);
  
       // Send message
       Transport transport = session.getTransport("smtps");
       transport.connect();
       transport.sendMessage(message, message.getAllRecipients());
       System.out.println("Sent message successfully....");
    }catch (MessagingException mex) {
       mex.printStackTrace();
    }
     }
  }
  </code></pre>