Sending emails using javamail connect failed: ETIMEDOUT (Connection timed out)
<p>OK so i'm having an issue here.  Sending emails in the background of my app works perfectly fine when i use 3G/4G network from the android but as soon as i connect it to wifi it no longer works and gives the connection timed out error.  none of the ports work on the android side and ive used telnet to connect using port 25 from my laptop over the same wifi network. not sure what the issue is here.</p>

<pre><code>javax.mail.MessagingException: Could not connect to SMTP host:      
smtp.gmail.com, port: 25;
12-22 13:31:11.861 5380-6822/com.apksrc.loot W/System.err:   nested 
exception is:
12-22 13:31:11.861 5380-6822/com.apksrc.loot W/System.err:   
java.net.ConnectException: failed to connect to   
smtp.gmail.com/2607:f8b0:4002:c0c::6c (port 25): connect failed: ETIMEDOUT  
(Connection timed out)
12-22 13:31:11.863 5380-6822/com.apksrc.loot W/System.err:     at com
</code></pre>

<p>and my code for sending the email is:</p>

<pre><code>     @Override
    protected Void doInBackground(Void... params) {

    Properties props = new Properties();

    props.put("mail.smtp.host","smtp.gmail.com");

    props.put("mail.smtp.starttls.enable","true");
    props.put("mail.smtp.ssl.enable","true");
    props.put("mail.smtp.auth","true");
    props.put("mail.smtp.port","25");

    session = Session.getInstance(props, new GMailAuthenticator(Config.EMAIL, Config.PASSWORD));
    session.setDebug(true);
    try{
        MimeMessage mm = new MimeMessage(session);
        mm.setFrom(new InternetAddress(Config.EMAIL));
        mm.addRecipient(Message.RecipientType.TO, new InternetAddress(email));
        mm.setSubject(subject);
        mm.setText(message);



        Transport.send(mm);
    }catch (MessagingException e){
        e.printStackTrace();
    }

    return null;
}

class GMailAuthenticator extends Authenticator {
    String user;
    String pw;
    public GMailAuthenticator (String username, String password)
    {
        super();
        this.user = username;
        this.pw = password;
    }
    public PasswordAuthentication getPasswordAuthentication()
    {
        return new PasswordAuthentication(user, pw);
    }
}
</code></pre>