This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

simple alternative to javamail for sending attachments on linux  RSS feed

 
Stephen Huey
Ranch Hand
Posts: 618
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I often use the code below to send myself emails from within Java. To send attachments from within Java code on Windows, I just exec a process that runs blat. Now I'm writing similar Java code on Linux, and I need an easy way to exec a process that runs a simple utility to attach a file to an email, because if I don't attach these delimited text files, they get messed up in the email body. Do you have any suggestions? At the Red Hat 8 Linux prompt, I see I have access to mail and sendmail, but after reading the man pages, it seems like they don't do attachments on the command line. Or is there a way to modify my simple code below so I wouldn't have to use something like JavaMail?


 
Stephen Huey
Ranch Hand
Posts: 618
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's a good and easy to follow solution for sending either text or image attachments in an email in Java:

http://www.rgagnon.com/javadetails/java-0083.html
 
steve Barf
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stephen,
I've tried your technique above and it works ok. Just a few questions :

1) Do you have to tidy up in any way, like close the connection/url ?

2) Is this reasonbly robust, I need to replace some SMTPClient code that doesn't always work.

3) The second set of pout's aren't sent are they

Steve
 
steve Barf
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anyone else answer these questions if Stephen is unavailable ?
 
steve Barf
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anybody ?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!