• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Mail Sending Issue...

 
Ranch Hand
Posts: 483
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?

 
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Either use setRecipients with one larger array, or use addRecipient for all three addresses.
 
Somnath Mallick
Ranch Hand
Posts: 483
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Somnath Mallick
Ranch Hand
Posts: 483
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 483
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok. Then how can i get rid of that error?
 
Rob Spoor
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 483
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 483
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 483
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 483
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is there a mail server running on port 25 on that machine?
 
Somnath Mallick
Ranch Hand
Posts: 483
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Either the mail server is running on a different port, or your colleague is mistaken.
 
Somnath Mallick
Ranch Hand
Posts: 483
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Could you please tell me how to check which port is running the SMTP?
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ask the system administrator.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic