aspose file tools*
The moose likes Java in General and the fly likes Java Mail query Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Java Mail query" Watch "Java Mail query" New topic
Author

Java Mail query

colin shuker
Ranch Hand

Joined: Apr 11, 2005
Posts: 744
Hi,

I'd like to be able to send emails to people from within a java application (for a project).
So far, I installed 1st Mail Server, then using the code (2 jars were added to classpath):


I was able to email myself, but other emails like hotmail addresses blocked the mail cause of something to do with spam.

So then I was looking at this...
authstmp

Which has a year service for £14.

The point is, I dont know how I put it together... Can I just use java with this authsmtp, or do I still need a mail server like 1st Mail Server as well,
which I only have 30 days on trial, so this is not good in the long run.

Can anyone explain the process for me before I make the purchase.
Thanks for any help/advice.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42264
    
  64
Yep, using your own mail server will not work if the receiving host uses something like SPF (which looks up MX records of the sending mail server).

I'm not familiar with the service you mentioned, but they should provide you with a username, password and server name (or IP address) of the outgoing server, all of which you'd plug into your code. That should be all that's required.


Ping & DNS - my free Android networking tools app
colin shuker
Ranch Hand

Joined: Apr 11, 2005
Posts: 744
Thanks, so to recap:

This authSmtp server is not a program I install on my pc, (like the 1st Mail Server), but is that company's actual server.
Then from java program, this sends message to their server which sends it to the intended email address.

Then I have this code...

So here I guess, under host section, I put in address of authSmtp's server,
and the last 2 will be username and password which they should provide.

I thought I would ask here first, since its java specific kind of, before I ask them anything.
Thanks, does this seem correct?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42264
    
  64
Yes, that's correct. I would expect that they have instructions on their site as well, maybe accessible after you sign up. It may be slightly more complicated if they use a SMTP over SSL, but not much.
colin shuker
Ranch Hand

Joined: Apr 11, 2005
Posts: 744
Thanks I got it paid for and setup, using:



I'm not sure if the port number line is correct, I just added that.
It says:
SMTP Server : mail.authsmtp.com
SMTP Ports : 23, 26, 2525 or 25 [not usually recommended]
I figured if the default is 80, then I should specify the actual port(maybe not?).

So, I used the username and password they supplied me, and tried to send myself an email:
And I got..

Exception in thread "main" javax.mail.MessagingException: 513 5.0.0 Your email system must authenticate before sending mail.


But also, all new accounts need to be verified which can take a few hours, so perhaps thats the problem.
I'll try it later tonight and see if theres any improvement.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42264
    
  64
You may need to authenticate in a slightly different way, by using an Authenticator. See the JavaMail FAQ for how to do that: http://java.sun.com/developer/onlineTraining/JavaMail/contents.html

By the way, the default port is 80 only for HTTP; for SMTP it's 25.
colin shuker
Ranch Hand

Joined: Apr 11, 2005
Posts: 744
Great, good stuff...

I see how it fits in with my existing code, I have null for the authentication thing,
so I need to do the MyAuthentication subclass next, gotta go to work, so I'll look at it when I get back.

Thanks for your kind help.
colin shuker
Ranch Hand

Joined: Apr 11, 2005
Posts: 744
Hi again, well I tried it but I get the same error:



I seem to have done what it asked for in the link, but it doesn't even call the getPasswordAuthentication() method, so I donno what to do now, any thoughts?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18651
    
    8

I'm surprised this wasn't in the examples you looked at:
colin shuker
Ranch Hand

Joined: Apr 11, 2005
Posts: 744
Thanks, that helps, but now I get this error...


Exception in thread "main" javax.mail.MessagingException: 500 5.0.0 Envelope From Address of <ac48894@mail.authsmtp.com> is not authorised - go to: http://control.authsmtp.com

But I'm trying to send from my pc, not from an email address, so I donno what to do now. ???
colin shuker
Ranch Hand

Joined: Apr 11, 2005
Posts: 744
Ooooooohhhhhh, I got it to work!!!


It was the 'email from address' that confused me, but I guess this is just the email address that the receiver sees when they get the message, and it gives them something to reply back to. I found some complete code...

webpage

I have to have this address added in the stmpServer. I'll keep you posted if I get stuck.

Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18651
    
    8

colin shuker wrote:I have to have this address added in the stmpServer.


Right, so the SMTP server you are using wants to make sure you aren't trying to send e-mail which appears to be from somebody else. Stealing e-mail addresses to use as "From" is a common spamming technique, so it's good that you aren't allowed to do that.
colin shuker
Ranch Hand

Joined: Apr 11, 2005
Posts: 744
Hmmm, but I'm allowed 10 or 15 email addresses, so couldn't I just use other peoples email addresses anyway?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java Mail query