简体   繁体   中英

Transport not work for sending smtp email in java

I am using :

transport.connect(getHost(), getPort(), getUsername(), getPassword()); 

to send email, but it always gives me the following exception:

class com.sun.mail.smtp.SMTPAddressFailedException: 503 This mail server requires authentication when attempting to send to a non-local e-mail address. Please check your mail client settings or contact your administrator to verify that the domain or address is defined for this server.

But actually I have provided the username and password above, and the username and password is right as I tested in thunderbird, it can send email well.

So what's my problem ? Please point me the right direction. Thanks

When creating the javax.mail.Session, be sure the given properties contain:

props.put("mail.smtp.auth", "true");

http://www.oracle.com/technetwork/java/javamail/faq/index.html#smtpauth

I think that you need to talk to the administrators of the mail server to see what is going on. You might be using the wrong port for instance. Or there might be some local policy that you need to observe ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM