File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Other JSE/JEE APIs and the fly likes Mail Sending Issue... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "Mail Sending Issue..." Watch "Mail Sending Issue..." New topic
Author

Mail Sending Issue...

Somnath Mallick
Ranch Hand

Joined: Mar 04, 2009
Posts: 477
Hi Everyone,

I am trying to send a mail sunig JavaMail API. But the problem is I am trying to send to 3 addresses and when the mail comes in i see only the 1st name in the To list, ie the mail would have only "to1" field in it and so i am not sure if the mails are reaching to2 and to3! Could you please tell me if the coding is correct?

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19670
    
  18

Either use setRecipients with one larger array, or use addRecipient for all three addresses.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Somnath Mallick
Ranch Hand

Joined: Mar 04, 2009
Posts: 477
Here I am facing some issues. I am apporaching the code in two ways and i am stuck here!

1. When I use InternetAddress as an object like:

and adding them to the sendRecipient Method like:

The line:

is causing an error! address is just an object and sendMessage method takes in only an Array!

2. When i use InternetAddress as an Array like:

and trying to add them to sendRecipient method:

I am getting an error because setRecipient method takes in only one object of InternetAddress!

So both ways i am stuck!
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41525
    
  53
You need to pay close attention to details. There are 4 applicable API methods: addRecipient, addRecipients, setRecipient and setRecipients. The "s" at the end of two of them matters.

Furthermore, you should use "Transport.send(Message)", not "Transport.send(Message, Address[])". See the javadocs of the latter to learn why.


Ping & DNS - my free Android networking tools app
Somnath Mallick
Ranch Hand

Joined: Mar 04, 2009
Posts: 477
I saw the Java Docs and after that did part 1 of my previous post! Because this throws an error! And if i don't provide any address then how would the transport know where to send the mails to?


Erorr:
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41525
    
  53
if i don't provide any address then how would the transport know where to send the mails to?

It knows that because all the addresses have been added to the message. If you read the javadocs for Transport.send(Message, Address[]) carefully, you'll notice that it disregards all addresses you added to the message, and will use the ones provided as part of the Transport.send call - which is not what you want.
Somnath Mallick
Ranch Hand

Joined: Mar 04, 2009
Posts: 477
Ok. Then how can i get rid of that error?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19670
    
  18

What are the properties used for connection: the SMTP server, port, user name and password? Are you sure a mail server is running on that server?

And because you are using setRecipient, you are still throwing away (overwriting) the first two. Please re-read Ulf's first post.
Somnath Mallick
Ranch Hand

Joined: Mar 04, 2009
Posts: 477
Well my details are given in the first post. I was using this code and these details for sending mails in another application. I just copy pasted the top part from the other code! So i can say it should work!
So since its getting overwritten... Would this work?
Somnath Mallick
Ranch Hand

Joined: Mar 04, 2009
Posts: 477
Thanks guys for all the help. I figured it out and made some changes and now its working fine! Also would like to know that would the same code work on Unix system?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19670
    
  18

It should, yes, unless you've programmed something for Windows only. The only thing that should be for this application is hard coded file paths.
Somnath Mallick
Ranch Hand

Joined: Mar 04, 2009
Posts: 477
Well i just cant seem to get it working for the SMTP server on UNIX.

I checked with the

I found that there is no port 25 there! Could that be a problem?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41525
    
  53
Well i just cant seem to get it working for the SMTP server on UNIX.

What does this mean? Is there smoke coming out of the server?

I checked with the
I found that there is no port 25 there! Could that be a problem?

On which machine did you do this? Are you still using the same mail server as in your first post?
Somnath Mallick
Ranch Hand

Joined: Mar 04, 2009
Posts: 477
No i changed it to the server name of the Unix (SunSolaris)! But somehow i get the error of unable to login or something!



Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41525
    
  53
Is there a mail server running on port 25 on that machine?
Somnath Mallick
Ranch Hand

Joined: Mar 04, 2009
Posts: 477
That's what i said in the previous post... I see no port 25 in the list! My colleague told me there's a mail server configured. But i cant say for sure!
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19670
    
  18

Either the mail server is running on a different port, or your colleague is mistaken.
Somnath Mallick
Ranch Hand

Joined: Mar 04, 2009
Posts: 477
Could you please tell me how to check which port is running the SMTP?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41525
    
  53
Ask the system administrator.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Mail Sending Issue...