bbottema / simple-java-mail

Simple API, Complex Emails (Jakarta Mail smtp wrapper)

Home Page:http://www.simplejavamail.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Test connection without sending email

stevenvanloon opened this issue · comments

Hi,

At this moment, I test whether a connection to the smtp server is valid or not, by executing this code:

public void testConnection() {
	try {
		Mailer mailer = createMailer();
		Session session = mailer.getSession();
		Transport transport = session.getTransport("smtp");
		try {
			transport.connect();
		} finally {
			transport.close();
		}
	} catch (MessagingException e) {
		... handle error ...
	}
}

That's why I need access to the Session object:

"Providing access to Session instance for emergency fall-back scenario. Please let us know why you need it."

Is there another way to do this without actually sending an email and without using the Session object?

Thanks,
Best regards,
Steven.

Not yet, but thanks for reporting. I think it's an interesting feature!

Implemented for version 5.0.0. Should also work with (authenticated) proxy!

Looks good!

Released as 5.0.0.rc1-SNAPSHOT. Add OSS' snapshots repo to find it in Maven.

The docs should say that an error causes a MailException to be thrown.

@mrj Indeed, I will update the documentation and Javadoc to indicate this. Thanks!