0

All..

I am asking this question, and yes it might look like a newbie posting a question without search first, but I have a caveat that I need to be considered before marking this as a repeat or duplicate of similar posted questions!

I have "googled" and searched on stackoverflow, and tried just about every combination of parameters and methods to get an email sent by either mail, mailx, or sendmail (don't care, will even consider other methods), and have the client recognize the email as HTML and properly display the message along with an attachment.

My request is to find a way to send an HTML email AND attach a file at the same time, with a single command.

I am using mail and mailx "12.4 7/29/08", and I can not figure out what version of sendmail. I am using "Linux 2.6.32-504.8.1.el6.x86_64" (RHEL 6.6 Santiago) build of RHEL.

Looking for any of the following?

  • How does one find a program that will allow me to send an email with HTML, attach a file and have it be detected my the email client as HTML with an attachment?
  • Format a message and its "body" content, and manually encode a file to be attached so that can be sent and have it be detected my the email client as HTML with an attachment?
  • Combination of both of the above?

I am stumped. Many of the posts I found have told me there is a large variety of mail and mailx versions and distributions that have different patterns. I am not porting this from machine to machine, and not looking for portable bash script code. However, I like writing clean code that is fairly portable and standard, but that would be like having my pie and eating it too! :-)

jewettg
  • 1,098
  • 11
  • 20
  • I am trying to get that kind of reputation! Gotta have time in the day, with life, kids, work, etc.. to answer questions! ;-) Too bad work on SpiceWorks and other forums do not count! – jewettg May 11 '15 at 13:31

1 Answers1

1

Mailx html content is in this theme Mailx send html message

Attachment her http://www.unix.com/solaris/183753-mailx-attachment.html

I understood this correctly?

Community
  • 1
  • 1
x93
  • 36
  • 4
  • Thank you x93, unfortunately, this article is the same that I have been finding. It offers up the same "-a" parameter with information like: -a 'Content-Type: text/html' which is not correct according to the most recent man page for mail or mailx: DESCRIPTION Mailx is .... also usable as a mail batch language, both for sending and receiving mail. The following options are accepted: -a file Attach the given file to the message. – jewettg May 11 '15 at 13:28
  • @jewettg Their solution doesn't work for you? I don't understand. Parameter -a should be add whatever allowed options to the html header options. For me working this code: `mailx -a 'Content-Type: text/html' -s "Subject email" your@mail – x93 May 14 '15 at 00:58
  • I wish I had the same version of mailx code that you do. The version I have (and I have tried your code) does accept "html header options" with the "-a" parameter. See the man page that look identical to mine: http://linux.die.net/man/1/mailx – jewettg May 14 '15 at 13:33
  • 1
    Which distribution you have linux? I recommend ,when you have other versions. You may use external editor, but is little bit harder way. In the theme http://unix.stackexchange.com/questions/15405/how-do-i-send-html-email-using-linux-mail-command#answer-15463 – x93 May 14 '15 at 14:34
  • Thanks for all the help x93! I am using RHEL 6.6, and it does not have that option or the option to provide HTML header options. On a positive note, I have worked around the issue by using a tool UT Campus has at its disposal -- UTBOX (box.com), where I can generate the query output as HTML and send it (using sendmail -t) using mime headers: ("Mime-Version: 1.0" "Content-Type: text/html"). Then I send a mail to UTBOX (cool feature to assign email addresses to specific folder) and send an email with the: mail -a parameter and specify a filename and it sends a mail with the attachment. ;-) – jewettg May 14 '15 at 14:51
  • Ok, yes problem is in Redhat distribution. So UT Campus ,can you add link on this api? – x93 May 14 '15 at 15:31
  • If you are referring to the box.com API for sending email to folders, here ya go: https://support.box.com/hc/en-us/articles/200520228-Uploading-Files-to-Box-with-Email – jewettg May 14 '15 at 17:00
  • But this api for GUI. I thought api for console, as your example with parametr -t. – x93 May 14 '15 at 17:50
  • You define the folder and the email address via the web GUI. Copy the email address, and anything you send to that email address will be filed into the appropriate folder. You can have as many folders as you want with unique email addresses. – jewettg May 14 '15 at 21:52
  • Here is the bash script code for the email to folder (using the above). echo "" | mail -a "$attachFile" -s "$eDate" -r "bacs_automation@utlist.utexas.edu" "upload.*******@u.box.com". Please make note of the echo "" piped to stdin of the mail command. If you do not do this, it will gobble up any other stdin that is being used for loops and causing unexpected termination of loops and such (learned the hard way). – jewettg May 15 '15 at 13:14
  • Command is ok but, still I don't understand so much, I am sorry. It is a cloud service email? Because in your link I not found, there are only references of GUI email client from cloud in Texas. You said, that this is api for email. There is no mention of bash command line. Maybe I am understood wrong. You sending email from linux console via email cloud client( box.com, or something like): Where did you get the command (bash)? Email cloud services are connected with linux, respectively are there these options? – x93 May 15 '15 at 22:11
  • Appendix: Maybe my ideas, if you using webdav, or custom script for remote access from linux to the box.com, but I don´t know.... – x93 May 15 '15 at 22:20
  • I apologize @x93. If you have a BOX (box.com) account, a cloud sync service, then you can take advantage of what I have been explaining. This is not a generic or anonymous service. So, if you have a BOX account, you can use this service, email files to a email address and it places it in the folder designated. – jewettg May 17 '15 at 16:33
  • Ok, well so sending from linux is connected this service? Respectively, is there some way how it use. I understand this now correctly? I doubt, that is it usual thing for most people.Where I can found mention of bash commands on the page api box.com. You are still don't said, where this I can find.Thank you! – x93 May 17 '15 at 21:32
  • You must have a free box account. Go to box.com for more details. Once you have an account, Please read this: [Email Notification from Box](https://support.box.com/hc/en-us/articles/200520278-How-do-I-manage-email-notifications-from-Box-). Confusion might be that this not an SMTP/sendmail service. This is just a cool way of delivering files to a target folder on Box.com! You use a a bash/Linux command-line or script to use sendmail or mail to send email to box and it will place the attached file into the appropriate folder. Cheers! – jewettg May 18 '15 at 13:36
  • Ok, that´s crap ,that I except some interface for direct custody on Linux. You using any usual probably default sender email bash script, which normally works and you used with combination function, folders box.com. Is it so? That´s seems as combination both solution. Cheer :) – x93 May 21 '15 at 23:29