This error is caused for one of two reasons: You are attempting to send email to a domain that is not recognized by this server You are attempting to relay email through this server, and have not authenticated Most likely you are seeing this message because you have not authenticated. To use this server as a relay (to send email to an outside address using your domain name), you must authenticate first. You can do this in one of two ways: SMTP Authentication - SMTP AUTH is a method for verifying a user's login and password before allowing Mail to be sent to other Mail Servers on the Internet. Your Email Client is required to login before sending mail. This method allows you to simply enter your Username and Password (the same ones you use for POP or IMAP) in the SMTP settings in your email program. POP before Send - This method allows you to simply check your email before sending. Once you have checked your email, you are allowed to relay for the next 15 minutes from your current IP address without further authentication.
Keep in mind that the Authenticator in JavaMail is different than the one in the java.net package. To use the javax.mail.Authenticator, the basic process to connect to the Store is as follows: // Create empty properties Properties props = new Properties(); props.put("mail.host", host);// Setup authentication, get session Authenticator auth = new PopupAuthenticator(); Session session = Session.getInstance( props, auth);// Get the store Store store = session.getStore("pop3"); store.connect();Then, you would need to create a PopupAuthenticator class that extends Authenticator. In the public PasswordAuthentication getPasswordAuthentication() method, the class would pop a frame up prompting for username and password, returning the information in a PasswordAuthentication object.
You are attempting to send email to a domain that is not recognized by this server
You are attempting to relay email through this server, and have not authenticated
Most likely you are seeing this message because you have not authenticated. To use this server as a relay (to send email to an outside address using your domain name), you must authenticate first. You can do this in one of two ways:
SMTP Authentication - SMTP AUTH is a method for verifying a user's login and password before allowing Mail to be sent to other Mail Servers on the Internet. Your Email Client is required to login before sending mail. This method allows you to simply enter your Username and Password (the same ones you use for POP or IMAP) in the SMTP settings in your email program.
POP before Send - This method allows you to simply check your email before sending. Once you have checked your email, you are allowed to relay for the next 15 minutes from your current IP address without further authentication.
这是因为你使用的smtp服务器加了认证,你必须拥有该服务器上合法的用户名和密码才能使用该服务器的smtp服务。
你要修改以下你的方法
props.put("mail.smtp.host", "smtp.sina.com.cn");
props.put("mail.smtp.auth", "true");。
transport.connect("smtp.sina.com.cn", "name","password")
Sending failed;
nested exception is:
javax.mail.AuthenticationFailedException
Properties props = new Properties();
props.put("mail.host", host);// Setup authentication, get session
Authenticator auth = new PopupAuthenticator();
Session session = Session.getInstance(
props, auth);// Get the store
Store store = session.getStore("pop3");
store.connect();Then, you would need to create a PopupAuthenticator class that extends Authenticator. In the public PasswordAuthentication getPasswordAuthentication() method, the class would pop a frame up prompting for username and password, returning the information in a PasswordAuthentication object.