1

I am using JavaMail API and I'm able to send mail from abc@gmail.com to xyz@gmail.com.

Now, what I want:

I want to send email from abc@rediffmail.com to xyz@mail.com etc / etc.

outgoing mail server : smtp.rediffmail.com

port no : 25

o/p :javax.mail.AuthenticationExcepetion ,

what change is necessary foe it or IS this possible or not .

Akarsh M
  • 1,629
  • 2
  • 24
  • 47
  • Hope this you get your answer from here: http://stackoverflow.com/questions/2020088/sending-email-in-android-using-javamail-api-without-using-the-default-built-in-a – Chintan Soni Oct 12 '13 at 07:01
  • I did this but I want to send mail to the other domain as I mention in my above query @shree202 – Akarsh M Oct 12 '13 at 07:10
  • I don't understand. You just change the "to" email address. What's the real question? – Simon Oct 12 '13 at 08:11
  • @Simon If I'll change the email address(yahoo.com) .... on that mail I'm not getting the mail but In gmail.com .... case .... I m getting the mail – Akarsh M Oct 12 '13 at 08:35
  • Check your junk mail folder – Simon Oct 12 '13 at 09:02

1 Answers1

0

Try this snippet changing your SMTP server. Yahoo: Outgoing Mail Server (SMTP): plus.smtp.mail.yahoo.com Use SSL, port: 465, use authentication.

Snippet:

    Properties props = new Properties();
    props.put("mail.smtp.user", myEmail);
    props.put("mail.smtp.host", smptServer);
    props.put("mail.smtp.port", port);
    props.put("mail.smtp.starttls.enable", "true");
    props.put("mail.smtp.auth", "true");
    props.put("mail.smtp.socketFactory.port", port);
    props.put("mail.smtp.socketFactory.class",
            "javax.net.ssl.SSLSocketFactory");
    props.put("mail.smtp.socketFactory.fallback", "false");

    SecurityManager security = System.getSecurityManager();

    try {
        Authenticator auth = new autentificadorSMTP();
        Session session = Session.getInstance(props, auth);
        // session.setDebug(true);

        MimeMessage msg = new MimeMessage(session);
        msg.setText(body);
        msg.setSubject(subject);
        msg.setFrom(new InternetAddress(myEmail));
        msg.addRecipient(Message.RecipientType.TO, new InternetAddress(
                toEmail));
        Transport.send(msg);
    } catch (Exception mex) {
        mex.printStackTrace();
    }

Util:

    private class authSMTP extends javax.mail.Authenticator {
    public PasswordAuthentication getPasswordAuthentication() {
        return new PasswordAuthentication(myEmail, myPass);
    }
}

Hope it helps!

jsanchez
  • 64
  • 5