JavaMail API connection to Mercury Mail server error - java

I am trying to connect to Mercury mail server with a java application and I am using JavaMail api. The connection is not successful and I’m getting this error in the log:
EHLO x.x.x.x
554 Invalid HELO format
Which means that it connects to the server but the helo format is not something that sever likes. I've tired to debug it and I got to this code in JavaMail “SMTPTransport” class which says:
serverOutput.write(cmdBytes);
serverOutput.write(CRLF);
serverOutput.flush();
and according to code:
private static final byte[] CRLF = { (byte)'\r', (byte)'\n' };
which seems consistent with RFC 821
I know that on windows \n has different meaning but I am not sure if this really is the root of problem? If it not then what can cause this?
I checked mail server with mail client and it works fine and I checked the code with James mails server and it also works fine!
JavaMail API version is: 1.4.5 (latest release)
Mercury/32 : 4.7

I did a Google search on 554 Invalid HELO format and got a ton of hits about your specific Mercury problem. It's a bug.
http://community.pmail.com/forums/thread/4136.aspx
http://www.mantisbt.org/bugs/view.php?id=9645
http://ellislab.com/codeigniter/forums/viewthread/153130/
etc...

You might need to check the logs on the server to figure out what it's really complaining about, but... One thing you can try is setting the mail.stmp.localhost property to the correct DNS host name for your machine. From the debug output it looks like your machine is unable to determine its own name and so is sending the IP address instead.

For me in a web project the PHPMailer() class was forcing Auth. Changing the Auth to false fixed it. Maybe check similar option for setting Auth to false in your language.
This is what I changed in my PHP code from true to false and adding sendmail_from in the php.ini file
$mail = new PHPMailer();
$mail->SMTPAuth = false;

Related

Capturing HTTP traffic using Fiddler from Java applicaiton

I'm having difficulty using Fiddler to diagnose a problem in a Java application to connect to Microsoft Graph's API. Here's my basic environment:
JDK: 1.8.0_131
Apache HttpClient: 4.4
Fiddler: 4.6
The endpoint I'm trying to reach is https://login.microsoftonline.com/common/oauth2/authorize The problem I have is that the traffic is not captured by Fiddler.
I've tried various things as suggested by Googling for this problem, but have not got it to work. In my application, I set the proxy settings as follows:
httpClientBuilder.setProxy(new HttpHost(proxyServer, proxyPort, proxyScheme));
httpClientBuilder.build();
If I use ("127.0.0.1", 8888, "https"): then the error that I see is:
Unrecognized SSL message, plaintext connection?
If I use
("127.0.0.1", 8888, "http"): then the error that I see is: I/O
exception (org.apache.http.conn.UnsupportedSchemeException) caught
when processing request to
{tls}->http://127.0.0.1:8888->https://login.microsoftonline.com:443:
http protocol is not supported
I've tried other things (for example "localhost", "localhost.", and so on as suggested, and setting: -Djsse.enableSNIExtension=false), but so far no luck. Hopefully I am missing something obvious! Thanks for any help.
It turns out that the second configuration for the proxy is the correct one to use (using "http"), but what I had forgotten was that I was setting a ConnectionSocketFactoryRegistry in my HttpClientBuilder. I had not registered a ConnectionSocketFactory for "http" and this caused the second configuration to fail. I added this to the HttpClientBuilder, and now I can see traffic being captured by Fiddler:
connectionSocketFactoryRegistryBuilder.register("http", new PlainConnectionSocketFactory());

How to find weblogic t3 adminurl

I have a weblogic folder, From this - How can i find the adminurl that I can use with the below command
java weblogic.Deployer –adminurl t3://server:7001 –username system –password weblogic –listapps
I tried looking into setupinfo.txt, portlist.ini - but somehow this did not help/work. How can get this working?
I get errors/exceptions like these (after few attempts)
The loading of the trusted certificate list raised a certificate parsing exception PKIX: Unsupported OID in the AlgorithmIdentifier object
Unable to connect to 'http://server:7001': Destination unreachable; java.net.ConnectException: Tried all: 1 addresses, but could not connect over HTTPS to server: localhost port: 7102; No available router to destination
based on setupinfo.txt, I am able to login to the web console - but I need to know how to get this command working with adminurl !!!
Thanks,
Got it, thanks Alex.
Steps
Find startscript.xml under your weblogic domain , search this file for "ADMIN_URL"
The same can be done by web console UI ..... Admin Console Login to AdminConsole->Server->Configuration->ListenPort (enable and note down the port)
Bingo.

Apache Commons Mail Erroring on Server Contact

I have a Java app that sends email via Apache Commons Email. The app works just find on my development environment, but when I deploy it to the server, I'm getting an error that Commons couldn't connect to the email server.
org.apache.commons.mail.EmailException: Sending the email to the following failed : 255.255.255.255 :587
...Error authenticating with server.
Just to be sure this wasn't my configuration, I've tried on 2 different email providers, 1) Our email company email provider 2) Gmail. Both work on my dev and both fail with the same message on the server.
I've tried several ports and IP combinations. I've turned SSL on and off. I've checked with our email provider. I'm left with a configuration of either the server or the network.
I work remotely so I'm not on the same network as our servers, but I the app works for me even if I am on VPN.
I've used telnet from within the server and I can connect to the email provider on the proper port.
Does anyone have anything else I can try?
Thanks.
Edit
The error I'm getting is an authentication error. Could there be a security setting to prevent the credentials from being passed?
Still sounds like a permission problem. Ports below 1024 are restricted. Start your app with sudo permission.
It appears I was missing 1 line of code.
Assume "email" is my mail object...
email.setSSL(true);
All is working now. I'm not sure why it wasn't working before.

550 Access denied - Invalid HELO name

I am using apace common mail API for sending html emails. following is my code.
public void sendHTMLMail(String to, String subject, String message , String from) throws EmailException
{
HtmlEmail email = new HtmlEmail();
email.setHostName(SMTP_HOST_NAME);
email.addTo(to);
email.setFrom(from, "just-flick");
email.setSubject(subject);
email.setSmtpPort(25);
email.setHtmlMsg(message);
email.setTextMsg("Your email client does not support HTML messages");
email.send();
}
But while running the program I am getting following error.
Exception in thread "main" org.apache.commons.mail.EmailException: Sending the e
mail to the following server failed : mail.just-flick.com:25
at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1242)
at org.apache.commons.mail.Email.send(Email.java:1267)
at bseller.mail.SendMail.sendHTMLMail(SendMail.java:105)
at bseller.mail.SendMail.main(SendMail.java:31)
Caused by: com.sun.mail.smtp.SMTPSendFailedException: 550 Access denied - Invali
d HELO name (See RFC2821 4.1.1.1)
at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:1388)
at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:959)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:583)
at javax.mail.Transport.send0(Transport.java:169)
at javax.mail.Transport.send(Transport.java:98)
at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1232)
... 3 more
Please help me to configure this problem.
Thanks
I've faced the same problem, and when i pass the name of client host everything became ok
i've add this line in my code:
props.put("mail.smtp.localhost", client or host name which connect to mail server);
Good Luck :)
This should be handled by the administrator of your mail server, not by you. Talk to whoever told you to connect to that mail server.
Maybe this will help:
email.getMailSession().getProperties().setProperty("mail.smtp.localhost", "www.example.com");
Of course replace www.example.com with the domain name of your host from where you send the mail.
However, as David Schwartz wrote, your mail configuration is not perfect either. Nowdays we do not submit mails to port 25. Port 587 is used for submission, which has more relaxed rules, although it may be necessary to authenticate yourself if your IP address is not white listed. Follow the link which was given by pst in his comment.
It is strange that JavaMail alone works, while Apache Commons Email does not, because I guess Commons Email also used JavaMail. This may indicate a bug somewhere but it would require further investigation.
One of your problem is that you do not know the exact HELO name you are sending. The following code may help to determine it, otherwise call your mail administrator (especially because he may advise you on port 587).
email.getMailSession().setDebug(true);
I was getting same error, it was fixed after enabling below properties:
spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.properties.mail.smtp.starttls.required=true
spring.mail.properties.mail.smtp.auth=true

Java: Question regarding apache commons mail

I am trying to send an email using Apache commons Email API.
I installed hMailServer as my smtp server and created a domain test.com. I added an user, 'user1' .
I tried to send the mail using the below code
public static void sendSimpleMail() throws Exception {
Email email = new SimpleEmail();
email.setSmtpPort(25);
email.setDebug(false);
email.setHostName("localhost");
email.setFrom("user1#test.com");
email.setSubject("Hi");
email.setMsg("This is a test mail ... :-)");
email.addTo("abc#gmail.com");
email.setTLS(true);
email.send();
System.out.println("Mail sent!");
}
When my program runs, it prints , "Mail sent!". But it has been about 30 minutes, but I haven't got the mail in my inbox.
Is there something I am missing ? Is there delay due to network problems ?
Update:
I ran diagnostics and I got the below details.
I think the problem might be with outbound port.
Can anyone help me figure what is going wrong?
There could be a number of problems. Since you didn't get an exception in your Java code, most likely the E-mail has reached your hMailServer instance, but hasn't gotten past that. The documentation for hMailServer includes a number of troubleshooting suggestions.
My best guess would be that your ISP (or your local firewall) is blocking outbound port 25. Also, be sure to check your spam folder on gmail.
Well take a look at the error: "mail.hmailserver.com could not be resolved" (AKA not found). Are you sure that's the correct address? Are you sure there's a mail server there?
BTW unless you have some HOSTS file enteries, that second failed test with "test.com" will never work. Use a real mail server

Categories