• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1071
  • Last Modified:

Authentication problem

Hello,
      I am sending my mails through smtp.
      If my mail host is mail.multi.net.pk
      it works well
      If my mail host smtp.dia.sbcglobal.net
      I get error
      javax.mail.MessagingException: 530 5.7.0 Authentication required

my code is

      String host = "smtp.dia.sbcglobal.net";
      String filename = gDesc.getString("email_attachment");
      String msgText1 = "asdasdasd";
     String subject = "email_subject";
     Properties props = System.getProperties();
                props.put("mail.smtp.host", host);
     Session session = Session.getDefaultInstance(props, null);
     session.setDebug(debug);
        try {
         MimeMessage msg = new MimeMessage(session);
         msg.setFrom(new InternetAddress(from));
            InternetAddress[] address = InternetAddress.parse(to);
         msg.setRecipients(Message.RecipientType.TO, address);
         msg.setSubject(subject);

            MimeBodyPart mbp1 = new MimeBodyPart();
            mbp1.setText(msgText1);
            Multipart mp = new MimeMultipart();
            mp.addBodyPart(mbp1);
            msg.setContent(mp);
            msg.setSentDate(new Date());
          Transport.send(msg);
        }
        catch (MessagingException mex)
        {
         mex.printStackTrace();
         Exception ex = null;
         if ((ex = mex.getNextException()) != null)
            {     ex.printStackTrace();         }
       }
I want to work this code smae with host as smtp.dia.sbcglobal.net
0
kamran
Asked:
kamran
  • 2
  • 2
2 Solutions
 
petmagdyCommented:
ok some Mail servers are configured to need an account in order to send SMTP, u need to add user and password to ur parameterized input, if an SMTP server dosn't need an account, just check with an (if condition) if the account parameters are not found or equal null

take a look at this link to see how to use the account (username and password)

http://www.websina.com/bugzero/kb/sunmail-properties.html
0
 
girionisCommented:
Try to set this property:

props.put("mail.smtp.auth","true");
0
 
petmagdyCommented:
I think I provided good advice here that may help solve the issue
0
 
girionisCommented:
I think my comment was the exact solution so I'd say a split 60%-40% between me and petmagdy.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now