How to check status of an SMTP server from Java? - java

In a Java program, what is the best way of determining if an SMTP server is ready to accept and send an email?

You can use JavaMail API and try to send an email.
If you don't want to actually send the email, you can open a TCP socket to port number 25 of your mail server and send the following commands:
HELO yourdomain.com
MAIL FROM: youremail#yourdomain.com
RCPT TO: recipient#recipientdomain.com
Make sure you check all server responses after each command issued. If you don't see any errors until that point, then probably you will be able to send emails with that SMTP server.
And, as Jordan Stewart kindly appointed:
You'll also want to make sure that the
HELO domain has a complementary A /
PTR dns record pair, with the IP
address the domain is mapped to being
the IP address you're connecting from.
The domain also needs at least one MX
record. I.e. if the server you're
connecting from is 123.45.67.89 then
you'd need an A record mapping
yourdomain.com to 123.45.67.89 and a
PTR ("reverse DNS") record mapping
123.45.67.89 back to yourdomain.com. If any of these conditions aren't met
you'll run into problems with some
mail servers as checks for these
things are anti-spam measures.

Related

Jmeter Error sent email on gmail

today i'm researching about the jmeter.
connect the gmail
login
send email
I passed 2 step and got error "java.net.UnknownHostException: mail.google.com" on step 3
Login :
Send Email :
I connected the link "mail.google.com" on the website.
Can somebody teach me what am i wrong ?
I would recommend using SMTP Sampler instead of simulating sending an email using web interface.
The relevant configuration would be:
Server: smtp.googlemail.com
Port: 587
Address from: your Gmail address
Address to: recipient address(es)
Check "Use Auth" and provide your full GMail username and password
Tick "Use StarTLS" radiobutton
Other fields are pretty much self-explanatory
References:
Set up Gmail with Outlook, Apple Mail, or other mail clients
Load Testing Your Email Server: How to Send and Receive E-mails with JMeter
I know this is not an answer you will like, but you should not be pointing any performance testing tool at a server you do not own, control or manage (or have permission from the people who do). In addition, Google's own end user agreement prohibits this behavior, supporting automation only with their published API set. License-wise and ethically, this is a problematic set of behavior for performance testing.
If you wish to experiment, then consider setting up a LAMP stack box inside of your own domain/control with an SMTP relay, pointing to mailbox destinations on that server. If you must test routing then setup two email servers with destinations on the opposite host (easy with two virtual machines).
Note, SMTP supports direct addressing, such as [name]#[host|IP address] so you can control directly any email routing to outside mailboxes accidentally and SPAMming individuals or organizations. This also avoids the problem of clogging up an SMTP relay with thousands of messages undeliverable due to lack of a valid address - this last condition will slow all email delivery for an organization and if not addressed can grind delivery to a halt before the first undeliverable messages start failing out after the delivery timeout is reached which is typically around 72 hours.

SMTP code 250 but email lost at remote server

I'm experiencing a weird issue with my mail server. Currently i'm using Apache James as a relay to dispatch emails to an external mail server. Sometime it happens that even if I receive an SMTP code 250 from the external mail server, the email diasappears and never get delivered or it is delivered after a very long time. Point is: am i right assuming that until i receive the SMTP code 250 of successful delivery from the external server, it is not a problem of my mail server?
Even you get SMTP return code 250, it doesn't guarantee your email will arrive in final destination.
That return code means that the relay server ACCEPTS your email-delivery request. After they accept the request, who knows what happen after that. Several possibilities:
The remote server scan your email with AntiSpam daemon and (unfortunately) your email is mis-idenfified as spam. So they discard/drop it.
The remote server just don't like your email. Maybe your IP Address blacklisted. So they silently discard it.
The remote server is busy processing other jobs. So they delay your email delivery.
The server happily to forward your email to final destination right now.
Further info: Simple_Mail_Transfer_Protocol on Wikipedia

Suddenly not able to send email by amazon SES - unable to connect smtp host

I am using Amazon SES from almost 4 months with same code, same port number(25) everything same. But from past 1 week I am not able to send email - while sending this error comes:
The email was not sent.
Error message: Could not connect to SMTP host: email-smtp.us-east-1.amazonaws.com, port: 25
I am using the same code for sending email that amazon suggests to use from link (http://docs.aws.amazon.com/ses/latest/DeveloperGuide/send-using-smtp-java.html)
We are working on a website project and using it inside it. Its not a problem with me alone, my team members of 4 working under same internet gateway, all of them are not able to send email from 1 week from their localhost.
But when we deploy the same code on Amazon ec2, top-level domain say sample.com then it starts working but when we deploy the same code under a sub-domain say beta.sample.com then again same error starts coming.
Does anyone have any idea about this?
Passing outgoing SMTP (25) port connections bloc
Try sending your email via email-smtp.us-east-1.amazonaws.com:587.
Outgoing connections to SMTP (25) port may be blocked by a firewall to stop outgoing spam.
Can you telnet any of the two ports? Do you get SMTP greeting messages?
telnet email-smtp.us-east-1.amazonaws.com 25
telnet email-smtp.us-east-1.amazonaws.com 587
https://en.wikipedia.org/wiki/Mail_submission_agent
Many Internet service providers and enterprise or institutional networks restrict the ability to connect to remote MTAs on port 25. The accessibility of a Mail Submission Agent on port 587[1] enables nomadic users to continue to send mail via their preferred submission servers even from within others' network

User registration mail using any email id

I have a registration page on my site. The users who register in my site, I want to send them a verification mail. I am able to send ail using my gmail id. But when I use my site mail id say www.xyz.com then mail is not getting sent please suggest me how to get it done.
First of all make sure your mail server is running, and if it linux server then grep your email ID from logs what you found as below: Replace Your#emailid with your email ID.
For exim:
grep YOUR#emailid /var/log/exim_mainlog
In Sendmail:
grep your#emailID /var/log/maillog
If you can send mails using the G-mail, then there is no issue with your script. As you are having issue with your own mail server or mail address, Make sure that exim or any other mail server is running on the server.
Also the domain say xyz.com is pointing to the server if it is having a MX as local domain.
For checking A record dig +trace xyz.com .Make sure that A record is points to the server.
For checking MX record dig +trace xyz.com MX . Make sure that MX is like "0 or 10 xyz.com"
Instead if it is using remote MX then make sure that you are using mail server IP as the remote mail server in the script.
Try sending mails using webmail client and make sure that there are no current issues with the mail mail server. like poor reputation or else.
In case domain is having remote MX, make sure that the your server IP is not listed in the firewall block of remote server.

Sending email in Java

I have read that to send email in Java I need to obtain my ISP's SMTP address, but if I am intending to host my web app online, will this be my hosts ISP SMTP address?
EDIT: So I need to find out my clients ISP's SMTP address and send via this?
JavaMail is the built-in API for e-mail.
Ask your ISP if the host runs sendmail or equivalent locally (the web server host). It may be an advantage to hand off to sendmail as early as possible. In other words, try "localhost" as the SMTP server name.
Why? JavaMail is a simple SMTP client. It doesn't deal with DNS MX records. It doesn't have a built-in capability to queue mail if the SMTP server is unavailable. There's the default Java infinte DNS cache so that a DNS change to the SMTP host won't register with your app (tunable, but one more tuning to do). These are things that a local sendmail (or equivalent) process will do.
So if you can hand off the e-mail to a local sendmail/equivalent, that may improve e-mail delivery reliability. Assuming the local sendmail works, of course. It's how we configure some in-house apps that uses JavaMail to send mail and fixed all the above problems.
No, unless your webhost is the same as your ISP or your webhost also offers SMTP services.
In response to your edit, yes you need your ISP's SMTP address by the sound of things.
It will be the SMTP address you want to forward email through.
If you want to send email through your ISP account then it will be that SMTP.

Categories