Advertisement

06.29.2008 at 10:42PM PDT, ID: 23525959
[x]
Attachment Details

JavaMail - com.sun.mail.smtp.SMjabaTPSendFailedException: 530 5.7.3 Client was not authenticated

Asked by namitabhandola in JavaMail, Simple Mail Transfer Protocol (SMTP), Java Naming & Directory Interface (JNDI)

Tags: java, IE

Hi,

Am trying to send a mail through java using a simple SMTP connection, but I am getting the following error.

530 5.7.3 Client was not authenticated
DEBUG SMTP: got response code 530, with response: 530 5.7.3 Client was not authenticated

RSET
250 2.0.0 Resetting
com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.3 Client was not authenticated

      at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:1515)
      at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:1054)
      at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:634)
      at javax.mail.Transport.send0(Transport.java:189)
      at javax.mail.Transport.send(Transport.java:118)
      at sendmailproject.Email.sendmail(Email.java:65)
      at sendmailproject.Email.main(Email.java:72)

I've tried setting/changing all the required properties, but am still getting the error. Any inputs on this will be really helpful. Attached is the code I am using.
Thanks!
Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
import java.util.Properties;
import javax.mail.Authenticator;
import javax.mail.Message;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
 
public class Email {
    private Session getMailSession() throws Exception {
        Properties mailProperties = new Properties();
        Authenticator auth = new SMTPAuthenticator();
        
        mailProperties.setProperty("mail.transport.protocol", "smtp");
        mailProperties.setProperty("mail.smtp.host", SMTP_HOST);
        mailProperties.put("mail.smtp.port", "25");
        mailProperties.put("mail.smtp.auth", "true");
        return Session.getInstance(mailProperties, auth);
    }
 
    public void sendmail() throws Exception {
        //MimeMessage msg = new MimeMessage(getMailSession());
        Session mailSession = (Session)getMailSession();
        mailSession.setDebug(true);
        //MimeMessage msg = new MimeMessage(getMailSession());
        MimeMessage msg = new MimeMessage(mailSession);
        msg.setFrom(new InternetAddress(SENDER_ADDRESS));
        msg.addRecipient(Message.RecipientType.TO, 
                         new InternetAddress(RECIPIENT_ADDRESS));
        msg.setSubject("test mail subject");
        msg.setText("test mail text");
        Transport.send(msg);
    }
 
    public static void main(String[] av) {
        Email mail = new Email();
        try {
            mail.sendmail();
            System.out.println("mail send successfully");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
class SMTPAuthenticator extends javax.mail.Authenticator { 
    private final String SMTP_AUTH_USER = USERNAME;
    private final String SMTP_AUTH_PWD = PASSWORD;
    
    public PasswordAuthentication getPasswordAuthentication() {
            String username = SMTP_AUTH_USER;
            String password = SMTP_AUTH_PWD;
            return new PasswordAuthentication(username, password);
    }
}
[+][-]06.29.2008 at 11:10PM PDT, ID: 21896940

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.29.2008 at 11:11PM PDT, ID: 21896945

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: JavaMail, Simple Mail Transfer Protocol (SMTP), Java Naming & Directory Interface (JNDI)
Tags: java, IE
Sign Up Now!
Solution Provided By: Bart_Cr
Participating Experts: 3
Solution Grade: B
 
 
[+][-]06.29.2008 at 11:21PM PDT, ID: 21896992

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.29.2008 at 11:59PM PDT, ID: 21897172

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628