Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Must issue a STARTTLS command first

Tags:

java

I am running this simple example with my Gmail account, but its not working and giving the following error:

      send failed, exception: com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.0 Must issue a STARTTLS command first. nv2sm4478384pbb.6       

Here is my code

   public class Email {    public static void main(String [] args)    {         Properties props = new Properties();         props.put("mail.smtp.host", "smtp.googlemail.com");         props.put("mail.from", "[email protected]");           Session session = Session.getInstance(props, null);          try {             MimeMessage msg = new MimeMessage(session);             msg.setFrom();             msg.setRecipients(Message.RecipientType.TO,                               "[email protected]");             msg.setSubject("JavaMail hello world example");             msg.setSentDate(new Date());             msg.setText("Hello, world!\n");             Transport.send(msg);         } catch (MessagingException mex) {             System.out.println("send failed, exception: " + mex);         }    } } 
like image 695
user1226162 Avatar asked May 09 '12 04:05

user1226162


People also ask

What is STARTTLS command in SMTP?

StartTLS is a protocol command used to inform the email server that the email client wants to upgrade from an insecure connection to a secure one using TLS or SSL. StartTLS is used with SMTP and IMAP, while POP3 uses the slightly different command for encryption, STLS.


1 Answers

You are probably attempting to use Gmail's servers on port 25 to deliver mail to a third party over an unauthenticated connection. Gmail doesn't let you do this, because then anybody could use Gmail's servers to send mail to anybody else. This is called an open relay and was a common enabler of spam in the early days. Open relays are no longer acceptable on the Internet.

You will need to ask your SMTP client to connect to Gmail using an authenticated connection, probably on port 587.

like image 181
Greg Hewgill Avatar answered Sep 30 '22 19:09

Greg Hewgill