0

I keep getting 550 5.7.1 Unable to relay for someUser@gmail.com

try { Properties p = System.getProperties();

        p.put("mail.smtp.host", "server IP");
        p.put("mail.smtp.port", "25");
        p.put("mail.debug", "true");
        Session s = Session.getDefaultInstance(p);

        Message msg = new MimeMessage(s);

        msg.setFrom(new InternetAddress(from));

        msg.setRecipient(Message.RecipientType.TO, new InternetAddress(to));

        msg.setSubject(subject);

        Multipart mp = new MimeMultipart();

        BodyPart bp = new MimeBodyPart();
        bp.setText(message);

        mp.addBodyPart(bp);

        msg.setContent(mp);

        Transport t = s.getTransport("smtp");
        t.send(msg);
        return 0;
    } catch (Exception e) {
        e.printStackTrace();
        return 1;
    }
debergalis
  • 11,870
  • 2
  • 49
  • 43

2 Answers2

1

you must login into your exchange smtp first.

String host = "smtp.gmail.com;
String username = "user";
String password = "passwd";
Properties props = new Properties();
props.put("mail.smtps.auth", "true");
// ...
MimeMessage msg = new MimeMessage(session);
// set the message content here
Transport t = session.getTransport("smtps");
try {
t.connect(host, username, password);
t.sendMessage(msg, msg.getAllRecipients());
} finally {
t.close();
}

or

change your exchange setting to allow you sending without login

Allowing application servers to relay off Exchange Server 2007 http://msexchangeteam.com/archive/2006/12/28/432013.aspx

ncowboy
  • 1,311
  • 2
  • 13
  • 19
0

Your exchange server probably doesn't allow relaying for the ip from which you are submitting to it? Or it might require authentication before relaying.

MK.
  • 33,605
  • 18
  • 74
  • 111
  • The IP from where im submitting is set and allowed. As for the authentication the Admin said its not required to send email. Im guessing there wrong. Now, continuing with the authentication how is that made posible? – Mike tuliany Jan 14 '11 at 22:31
  • Hm... try looking at this question maybe http://stackoverflow.com/questions/4337812/javamail-ntlm-authentication-failure NTLM is what exchange usually wants. – MK. Jan 15 '11 at 00:03