JavaMail send mail without using default port 25

  • Thread starter Nicola Trevisan
  • Start date
N

Nicola Trevisan

Hi,
I must send email to a server that listen in port 2025,
how I can do it using JavaMail??

Thank to all.
Nicola Trevisan

PS: I insert my code so you can tell me where to place new code.....I hope

props = System.getProperties();
props.setProperty("mail.transport.protocol", "smtp");
props.setProperty("mail.host", "127.0.0.1");
session = Session.getDefaultInstance(props);
in = new FileInputStream(file);
msg = new MimeMessage(session, in);
msg.setFrom(new InternetAddress("(e-mail address removed)"));
msg.setRecipient(Message.RecipientType.TO, new
InternetAddress("(e-mail address removed)"));
transport = session.getTransport();
transport.send(msg);
 
R

Roedy Green

I must send email to a server that listen in port 2025,
how I can do it using JavaMail??

Store store = session.getStore( receiveProtocol );
store.connect( receiveHost, receivePort, receiveLoginID,
receivePassword );


Transport transport = session.getTransport( sendProtocol );
transport.connect( sendHost, sendPort, sendLoginID, sendPassword );
 
N

Nicola Trevisan

It doesn't work!!!
I try, but I have error like this:

javax.mail.SendFailedException: Sending failed;
nested exception is:
javax.mail.MessagingException: Could not connect to SMTP host: 127.0.0.1,
port: 25;
nested exception is:
java.net.ConnectException: Connection refused: connect

Can you give me a full code example???
I think I not open properly my session.

Thank
Nicola Trevisan
 
Y

Yu SONG

Nicola said:
It doesn't work!!!
I try, but I have error like this:

javax.mail.SendFailedException: Sending failed;
nested exception is:
javax.mail.MessagingException: Could not connect to SMTP host: 127.0.0.1,
port: 25;
nested exception is:
java.net.ConnectException: Connection refused: connect

Can you give me a full code example???
I think I not open properly my session.

Thank
Nicola Trevisan

Have you installed a SMTP server listening on 127.0.0.1:25 ?
 
Y

Yu SONG

Nicola said:
It doesn't work!!!
I try, but I have error like this:

javax.mail.SendFailedException: Sending failed;
nested exception is:
javax.mail.MessagingException: Could not connect to SMTP host: 127.0.0.1,
port: 25;
nested exception is:
java.net.ConnectException: Connection refused: connect

Can you give me a full code example???
I think I not open properly my session.

Thank
Nicola Trevisan

try this,

props.put("mail.smtp.port", "2025");
 
J

Jeeves

Hi,
I must send email to a server that listen in port 2025,
how I can do it using JavaMail??

If you want to send email to a server that listens on a non standard
port you are out of luck. You can specify which port to connect to
for your *local* smtp relay (per the other replies), but if it is the
remote server that listens on a non-standard port it cannot be done
with Javamail.
 
R

Roedy Green

javax.mail.MessagingException: Could not connect to SMTP host: 127.0.0.1,

That does not sound like a very likely host. Do you have a mailserver
running locally?

About the only other trick is this.

Properties props = System.getProperties();
if ( CustConfig.needPasswordToSend )
{
props.setProperty ( "mail.smtp.auth", "true" );
}
// Get a Session object
session = Session.getDefaultInstance( props, null );


I do have complete working example, but the source is not free.
See http://mindprod.com/products.html#BULK

See http://mindprod.com/jgloss/javamail.html

and follow the link to the tutorial. The docs are impossible, but the
tutorial is fairly easy to follow.
 
R

Roedy Green

If you want to send email to a server that listens on a non standard
port you are out of luck. You can specify which port to connect to
for your *local* smtp relay (per the other replies), but if it is the
remote server that listens on a non-standard port it cannot be done
with Javamail.

Why would it ignore your port specification?
 
J

Jeeves

Why would it ignore your port specification?

It shouldn't, but with port 25 increasingly blocked by ISPs it is
conceivable that a server would listen on a non-standard port and
some 3rd party perform a redirect-type enhanced DNS service, for
example. I would add that my followup was only based on the poster
writing, "I must send email to a server that listen in port 2025" and
does not mention anything about their own relay. I just assumed
they're testing something out especially as the 127.0.0.1 address in
the exception is a dead giveaway they are not setting a local smtp
server. I think they they Javamail sends directly.

I would add to the original poster a potential hack: that they could
do an MX lookup on the domain they are sending do, enter that as
their mail host property, set the port property to 2025 and that
*should* work. Because it is inbound mail to that server the SMTP
transaction would be the same as your own relay sending it on.
 
R

Roedy Green

I would add to the original poster a potential hack: that they could
do an MX lookup on the domain they are sending do, enter that as
their mail host property, set the port property to 2025 and that
*should* work. Because it is inbound mail to that server the SMTP
transaction would be the same as your own relay sending it on.

However, you are now doing the work of the mailserver. If it is down,
you are supposed to try later. You are supposed to be able to send all
your mail to one server and have it distribute it.

Perhaps the practical way out is to have a local mailserver, or a
local proxy mailserver such as the one that comes with Zaep.
 
N

Nicola Trevisan

THANK TO ALL!!

I must describe you what I must to do. (and sorry for my english)

I must test some anti-spam product for my thesis.
Now I work in local and I have a Local MailServer and a program that is an
anti-spam SMTP.

I write a program like an "smtp stress", but I send a database of e-mail.
I must test what e-mail are view as spam and what as legal e-mail.

I take advantage from the situation to ask you if you know some anti-spam
program, to test it.
They must be anti-spam that work in SMTP so not for the home user.

I tell you thank again!!
Bye
Nicola Trevisan
 
N

Nicola Trevisan

I try what tell me Yu SONG and it work!
Thank you Yu SONG, thank you very much.

I can't try to send the mail to another server....because I have only my PC.

Have a nice day!!!
Nicola
 

jal

Joined
Apr 2, 2011
Messages
1
Reaction score
0
correction concerning smtp port 25

You are not out of luck if your remote smtp host is not on port 25.

Here is a sample context.xml entry that works for eatj.com on port 587:

<Resource name="mail/Session" type="javax.mail.Session" auth="Container" mail.smtp.host="s98.eatj.com" mail.smtp.port="587" mail.smtp.auth="true" username="(e-mail address removed)" password="pw" mail.user="(e-mail address removed)" mail.password="pw" mail.transport.protocol="smtp" mail.debug="true"/>

Notes: eatj s98 usernames are the entire email address--most of the time you only enter the user part, but eatj is a bit unusal here.

What is a difficult parameter to find info on is the mail.smtp.port="587". I have seen lots of documents about the mail.port parameter and it does not work for changing from the default smtp port. Only the mail.smtp.port parameter allows this and this may be the only document on the net that talks about. I found nothing--just purely guessed at it. Now there is at least one doc.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,962
Messages
2,570,134
Members
46,692
Latest member
JenniferTi

Latest Threads

Top