Post new topic Reply to topic  [ 11 posts ] 
Author Message
 Post subject: stuck getting "530 SMTP authentication is required"
PostPosted: 2011-11-21 02:00 
New user
New user

Joined: 2011-11-19 17:56
Posts: 7
Hello. I am using hMailServer to send email from my website (Java Mail) to my web site users. I have only been able to make it work by perpetrating a critical configuration error--allowing external-to-external deliveries without SMTP authentication. But now I want to clean this up. Can someone please advise all the steps needed? I have these questions:

Does the sender need an account within the domain?
Does the sender need a password?
Does the Java Mail request need to include the password when sending?
or is SMTP authentication unrelated to accounts and senders?

AND why does hMailServer think my outgoing emails are external-to-external?

Thanks for helping a beginner!

regards,
eli


Top
 Profile  
 
 Post subject: Re: stuck getting "530 SMTP authentication is required"
PostPosted: 2011-11-21 02:34 
Developer
Developer

Joined: 2010-04-24 23:16
Posts: 6163
Location: Michigan, USA
Immediately reset the IP ranges to defaults with the defaults button or you will become an open relay for spam.
You DO NOT want to allow external to external.

The proper way to get around the auth req'd is (drumroll please) is to AUTH. In other words login to send. Pretty much any email client has that option even webmail.

The 2nd best method around it is if the IP is static & trusted (including a local private IP on your network or even 127.0.0.1 localhost) us to add a new IP range where auth is not required for all but external to external but extreme care needs to be taken. Be sure the sending domain is defined in hmail so hmail considers it local.
Bill

_________________
hMailServer build LIVE on my servers: 5.4-B2014050402
Latest test builds: http://www.hmailserver.com/forum/viewtopic.php?f=10&t=21420
Urgent? Bored? JOIN US ON IRC!
DOGE ME: DSqtEcqP3Qv6Tj2XrGNpDmEUkSBcpBsuWk


Top
 Profile  
 
 Post subject: Re: stuck getting "530 SMTP authentication is required"
PostPosted: 2011-11-21 03:29 
New user
New user

Joined: 2011-11-19 17:56
Posts: 7
Thank you Bill from Michigan. Can you confirm that by "AUTH" you mean I should build a user-name and password into the sending email-sending components in my web site?

TIA


Top
 Profile  
 
 Post subject: Re: stuck getting "530 SMTP authentication is required"
PostPosted: 2011-11-21 04:49 
Developer
Developer

Joined: 2010-04-24 23:16
Posts: 6163
Location: Michigan, USA
elisokal wrote:
Thank you Bill from Michigan. Can you confirm that by "AUTH" you mean I should build a user-name and password into the sending email-sending components in my web site?

TIA

Yes indeed you want to login using a user/pass defined in your hmail setup. Ideally each user should log in with their own user/pass when sending but in the event you need to put 1 user/pass just setup a user for that purpose.
Bill

_________________
hMailServer build LIVE on my servers: 5.4-B2014050402
Latest test builds: http://www.hmailserver.com/forum/viewtopic.php?f=10&t=21420
Urgent? Bored? JOIN US ON IRC!
DOGE ME: DSqtEcqP3Qv6Tj2XrGNpDmEUkSBcpBsuWk


Top
 Profile  
 
 Post subject: Re: stuck getting "530 SMTP authentication is required"
PostPosted: 2011-11-21 05:23 
New user
New user

Joined: 2011-11-19 17:56
Posts: 7
Thanks. A lot. I can send email now, but the solution does not make sense. TIA if anyone feels like reviewing this.

I built user/password authentication into my sending app according to the Java Mail docs. It all
made sense. But I was still getting 530's and my Java authentication callbacks were *NOT* getting called. Ready to give up in disgust, I unchecked "Require SMTP auth" for [x]Local to external e-mail addresses on the default Internet IP range and for whatever reason, my emails started going out.

Well I suppose I still don't have the authentication right, and the checkbox is a handy work-around.

Anybody out there with Java Mail know-how that can tell what I did wrong? Here's my OutgoingEMail class. THANKS.

package com.osx.web;

import java.net.InetAddress;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.logging.Level;

import javax.mail.Authenticator;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

public class OutboundEMail {

private static class OsxMailAuthenticator extends Authenticator {
private String userId;
private String pw;
public OsxMailAuthenticator( String userId, String pw ) {
this.userId = userId;
this.pw = pw;
}
public final String getUserId() {
return userId;
}
public final String getPw() {
return pw;
}

@Override
protected PasswordAuthentication getPasswordAuthentication() {
PasswordAuthentication ret = new PasswordAuthentication( userId, pw );
SiteAdmin.logMsg( Level.ALL,
String.format( "Sending %s/%s to authentication request from SMTP",
userId, pw )
);
return ret;
}
}

private static final Map< String, String > pwMap;
static {
pwMap = new HashMap< String, String >();
pwMap.put( "[email protected]", (it's a secret) );
}

private String sender;
private String addressee;
private String subject;
private String message;
private String mailServer;

boolean sent = false;

public OutboundEMail( String sender, String addressee, String subject,
String message ) {

this.sender = sender;
this.addressee = addressee;
this.message = message;
this.subject = subject;

this.mailServer = OsxWebProperties.get().getProperty( "MAIL_SERVER" );
}

public boolean send() {
boolean ret = false;
Properties props = new Properties();
props.put( "mail.smtp.host", mailServer );
props.put( "mail.from", sender );

String pw = pwMap.get( sender );
Authenticator auth = new OsxMailAuthenticator( sender, pw );

Session session = Session.getInstance( props, auth );

String detail = String.format(
"sender: %s\r\n" +
"addressee: %s\r\n" +
"subject: %s\r\n" +
"mailServer: %s\r\n",
sender, addressee, subject, mailServer
);

try {
MimeMessage msg = new MimeMessage( session );
msg.setFrom( new InternetAddress( sender ) );
msg.setSender( new InternetAddress( sender ) );
msg.setRecipients( Message.RecipientType.TO,
addressee );
msg.setSubject( subject );
msg.setSentDate( new Date() );
msg.setText( message );
Transport.send( msg );
ret = sent = true;
SiteAdmin.logMsg( Level.ALL, "Sent:\r\n" + detail );

} catch ( MessagingException mex ) {
String err = String.format(
"Failure to send email:\r\n%s", detail
);
SiteAdmin.logException( new CommException( err, mex ) );
}
return ret;
}
public final String getSender() {
return sender;
}

public final String getAddressee() {
return addressee;
}

public final String getMessage() {
return message;
}

public final String getMailServer() {
return mailServer;
}

public final String getSubject() {
return subject;
}

public final boolean isSent() {
return sent;
}
public final void setMailServer(String mailServer) {
this.mailServer = mailServer;
}
}


Top
 Profile  
 
 Post subject: Re: stuck getting "530 SMTP authentication is required"
PostPosted: 2011-11-21 07:23 
Moderator
User avatar

Joined: 2007-06-14 05:12
Posts: 11891
Location: 'The Outback' Australia
Can you please show some logs of the 530 rejections that you are getting

Ideally, enable SMTP, application and TCP/IP logging, repeat what gives you the rejection, wait 30 seconds and post the logs

_________________
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
Documentation


Top
 Profile  
 
 Post subject: Re: stuck getting "530 SMTP authentication is required"
PostPosted: 2011-11-21 09:57 
New user
New user

Joined: 2011-11-19 17:56
Posts: 7
Mattg - here are the logs you suggested, TIA

hMailServer:
"TCPIP" 1964 "2011-11-21 02:50:10.211" "TCPConnection - Posting AcceptEx on 0.0.0.0:25"
"DEBUG" 1964 "2011-11-21 02:50:10.226" "Creating session 92"
"SMTPD" 1964 92 "2011-11-21 02:50:10.226" "69.64.94.112" "SENT: 220 osx1.onlinesoftworx.com ESMTP"
"SMTPD" 1960 92 "2011-11-21 02:50:10.226" "69.64.94.112" "RECEIVED: EHLO osx1"
"SMTPD" 1960 92 "2011-11-21 02:50:10.226" "69.64.94.112" "SENT: 250-osx1.onlinesoftworx.com[nl]250-SIZE 20480000[nl]250 AUTH LOGIN"
"SMTPD" 1960 92 "2011-11-21 02:50:10.226" "69.64.94.112" "RECEIVED: MAIL FROM:<[email protected]>"
"DEBUG" 1960 "2011-11-21 02:50:10.226" "Total spam score: 0"
"SMTPD" 1960 92 "2011-11-21 02:50:10.226" "69.64.94.112" "SENT: 250 OK"
"SMTPD" 1964 92 "2011-11-21 02:50:10.226" "69.64.94.112" "RECEIVED: RCPT TO:<[email protected]>"
"SMTPD" 1964 92 "2011-11-21 02:50:10.226" "69.64.94.112" "SENT: 530 SMTP authentication is required."
"SMTPD" 1980 92 "2011-11-21 02:50:10.226" "69.64.94.112" "RECEIVED: RSET"
"DEBUG" 1980 "2011-11-21 02:50:10.226" "Deleting message file"
"SMTPD" 1980 92 "2011-11-21 02:50:10.226" "69.64.94.112" "SENT: 250 OK"
"SMTPD" 1976 92 "2011-11-21 02:50:10.226" "69.64.94.112" "RECEIVED: QUIT"
"SMTPD" 1976 92 "2011-11-21 02:50:10.226" "69.64.94.112" "SENT: 221 goodbye"
"DEBUG" 1964 "2011-11-21 02:50:10.226" "Closing TCP/IP socket"
"DEBUG" 1964 "2011-11-21 02:50:10.226" "Ending session 92"

Java Mail client
2011-11-21 02:50:10.10 SEVERE CommException: Failure to send email:
sender: [email protected]
addressee: [email protected]
subject: testing 02:47:27.464
mailServer: smtp.onlinesoftworx.net
2011-11-21 02:50:10.10 SEVERE Trap Level 1
com.osx.web.OutboundEMail.send(OutboundEMail.java:106)
com.osx.web.EmailTest.onClick$emailTest(EmailTest.java:37)

:

2011-11-21 02:50:10.10 SEVERE SendFailedException: Invalid Addresses
2011-11-21 02:50:10.10 SEVERE Trap Level 2
com.sun.mail.smtp.SMTPTransport.rcptTo(SMTPTransport.java:1835)
com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1098)
javax.mail.Transport.send0(Transport.java:195)
javax.mail.Transport.send(Transport.java:124)
com.osx.web.OutboundEMail.send(OutboundEMail.java:98)
com.osx.web.EmailTest.onClick$emailTest(EmailTest.java:37)

:

2011-11-21 02:50:10.10 SEVERE SMTPAddressFailedException: 530 SMTP authentication is required.
2011-11-21 02:50:10.10 SEVERE Trap Level 3
com.sun.mail.smtp.SMTPTransport.rcptTo(SMTPTransport.java:1733)
com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1098)
javax.mail.Transport.send0(Transport.java:195)
javax.mail.Transport.send(Transport.java:124)
com.osx.web.OutboundEMail.send(OutboundEMail.java:98)
com.osx.web.EmailTest.onClick$emailTest(EmailTest.java:37)


Top
 Profile  
 
 Post subject: Re: stuck getting "530 SMTP authentication is required"
PostPosted: 2011-11-21 10:22 
Site Admin
User avatar

Joined: 2005-07-29 16:18
Posts: 13809
Location: UK
Your script is not authenticating, You need to either make it auth with the account password or you need to add a new ip range with the upper and lower ip being 69.64.94.112 with a priority of 30 then disable authentication for that ip range. What this will do is allow your script to send email from that ip only while still requiring auth from all other ips.

_________________
If at first you don't succeed, bomb disposal probably isn't for you! ヅ


Top
 Profile  
 
 Post subject: Re: stuck getting "530 SMTP authentication is required"
PostPosted: 2011-11-21 10:29 
New user
New user

Joined: 2011-11-19 17:56
Posts: 7
Thanks ^Doom^
I had coded the authentication in my Java Mail sender but must have missed a step. Many thanks in advance if anyone can tell why my OutgoingEmail code posted above is failing to authenticate.


Top
 Profile  
 
 Post subject: Re: stuck getting "530 SMTP authentication is required"
PostPosted: 2011-11-21 11:16 
Moderator
User avatar

Joined: 2007-06-14 05:12
Posts: 11891
Location: 'The Outback' Australia
elisokal wrote:
Many thanks in advance if anyone can tell why my OutgoingEmail code posted above is failing to authenticate.

Perhaps you can check with Java support...

There may be more people there who know how Java Outgoing Email works.
Certainly in VB and .NET, you need to do more than just declare a FROM to send with Authentication

_________________
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
Documentation


Top
 Profile  
 
 Post subject: Re: stuck getting "530 SMTP authentication is required"
PostPosted: 2013-02-09 06:08 
New user
New user

Joined: 2013-02-09 05:58
Posts: 1
Location: Burke, VA
FYI to help folks in the future. I battled this for several hours until I found hints from viewing multiple supposed solutions. I was also able to compare the javax email to a .Net program both of which used hMailServer in the same configuration. The issue is that the javax does not use the userid and password set in the Transport object to answer hMailServer's auth call. Indeed, javax does not respond at all so this is considered a failure by HMS and the connection is cancelled. Turning off auth required in HMS of course works but this will not satisfy many corporate security requirements. I finally got it working when I noticed that someone else had set a property in javax for auth and also the transport user/pw. The property is "mail.smtp.auth" set to "true".

My method is below in case it helps:

Code:


   private static String doSendEmailNotices(ArrayList<String> emailaddresses, String emailbody, String subj) throws IOException, Exception {
      String msg= "", txt= "", txt1= "", emailserver= "", emailuserid= "", emailpw= "", emailfrom= "";
      int i, n1, emailport = 25, nto=0;
      Properties properties;
      Session session;
      MimeMessage emailmsg;
      Transport tport = null;
      LinkedHashMap<String, Integer> hashtemp = new LinkedHashMap<String, Integer>();
      try {
         //emailfrom must be a valid address or it is flagged as spam
         if (DiscoveryApp.hashconfig.containsKey("email.server")) emailserver= DiscoveryApp.hashconfig.get("email.server");
         if (DiscoveryApp.hashconfig.containsKey("email.pw")) emailpw= DiscoveryApp.hashconfig.get("email.pw");
         if (DiscoveryApp.hashconfig.containsKey("email.userid")) emailuserid= DiscoveryApp.hashconfig.get("email.userid");
         if (DiscoveryApp.hashconfig.containsKey("email.from")) emailfrom= DiscoveryApp.hashconfig.get("email.from");
         if (DiscoveryApp.hashconfig.containsKey("email.port")){
            txt1=DiscoveryApp.hashconfig.get("email.port");
            if (DSFunction.IsNumberString(txt1, "integer")) {
               emailport = Integer.parseInt(txt1);
            }
         }
         properties = System.getProperties();
         properties.setProperty("mail.smtp.host", emailserver); 
         properties.setProperty("mail.smtp.port", String.valueOf(emailport)); 
         properties.setProperty("mail.smtp.auth", "true");  //required to force javax to respond to request for AUTH         
         session = Session.getInstance(properties); // Get the default Session object.         
         emailmsg = new MimeMessage(session);  // Create a default MimeMessage object.
         // Set the RFC 822 "From" header field using the value of the InternetAddress.getLocalAddress method.
         emailmsg.setFrom(new InternetAddress(emailfrom));          
         emailmsg.setReplyTo(new InternetAddress[]{new InternetAddress(emailfrom)});
         emailmsg.setSubject(subj);
         emailmsg.setText(emailbody);
         emailmsg.setSentDate(new Date());
         hashtemp.clear();
         for (i = 0; i < emailaddresses.size(); i++) {
            txt = emailaddresses.get(i);
            if (!txt.equals("")) txt = txt.trim();
            n1 = txt.indexOf("@");
            if (n1 > -1 && txt.length() > n1) {
               txt1 = txt.toLowerCase();
               if (!hashtemp.containsKey(txt1)) {
                  nto++;
                  hashtemp.put(txt1, hashtemp.size());
                  emailmsg.addRecipient(Message.RecipientType.TO, new InternetAddress(txt));
               }
            }
         }
         if (nto== 0) {
            throw new Exception("no recipients defined for email message");
         }
         // Send message
         try {
            tport= session.getTransport("smtp");
            tport.connect(emailserver, emailuserid, emailpw);
            tport.sendMessage(emailmsg, emailmsg.getAllRecipients());
         }
         catch (Exception ex) {
         }
         finally {
            tport.close();
         }
      }
      catch (IOException ioex){
         msg= "notok:" + ioex.getLocalizedMessage();
      }
      catch (Exception ex) {
         msg = "notok:" + ex.getMessage();
      }
      return msg;
   }



Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 11 posts ] 


Who is online

Users browsing this forum: webguyz and 3 guests



Search for:
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group