Sponsored Content
Full Discussion: sendmail with attachments
Top Forums Shell Programming and Scripting sendmail with attachments Post 302350510 by suthera on Friday 4th of September 2009 05:30:43 AM
Old 09-04-2009
sendmail with attachments

Hi,

I got the following script from Ygor on this site:


Code:
#!/usr/bin/ksh

export MAILTO="email_address"
export CONTENT="/export/home/aisdba/email_body.html"
export SUBJECT="subject of email"
(
 echo "Subject: $SUBJECT"
 echo "MIME-Version: 1.0"
 echo "Content-Type: text/html"
 echo "Content-Disposition: inline"
 cat $CONTENT
) | /usr/sbin/sendmail $MAILTO

It works perfectly and means you don't need to use MIME to format the body of the email message you just use the HTML file defined in the CONTENT section above (its brilliant).

HOWEVER

I need to send the email with an attachment, now this is not the same file used for the body of the email rather a completely different file e.g. a txt file say. The following doesn't work:

Code:
#!/usr/bin/ksh

export MAILTO="email_address"
export CONTENT="/export/home/aisdba/email_body.html"
export SUBJECT="subject of email"
(
 echo "Subject: $SUBJECT"
 echo "MIME-Version: 1.0"
 echo "Content-Type: text/html"
 echo "Content-Disposition: inline"
 cat $CONTENT
) | /usr/sbin/sendmail $MAILTO > /file_location/filename.txt


It just messes with the body of the email and causes HTML code to be displayed rather than interpreted by Outlook.

Any ideas on how to keep the HTML interpreted in the body of the email and send the email with an attachment?

Thanks
Alec

Last edited by Ygor; 09-06-2009 at 10:23 PM.. Reason: Added CODE tags.
 

10 More Discussions You Might Find Interesting

1. Post Here to Contact Site Administrators and Moderators

Attachments

Hi I find that the attachment size are very limited. For eg, if we wish to analyse explorers from Sun systems or messages file, definitely they will exceed the given 3.5MB .. Dun you think so?:p (6 Replies)
Discussion started by: incredible
6 Replies

2. UNIX for Dummies Questions & Answers

sendmail attachments

Dear all, I've been working with AIX for, um, 15 years now and I have read all I can about the above, but I am stuck. Everything seems to point to using sendmail on the command line to embed a uuencoded attatchment will not work. Using something like "(cat plain.txt;uuencode attach.file... (4 Replies)
Discussion started by: rbatte1
4 Replies

3. UNIX and Linux Applications

Attachments in MUTT.

Can any body figure out how to attach the attachments mails while drafting them in MUTT form any location on my system. I am not able to figure it out. (0 Replies)
Discussion started by: nixhead
0 Replies

4. Shell Programming and Scripting

Sendmail Script: Gmail cannot find attachments

Hi. I am using a script on HP-UX to send emails that include a Pdf attachment to clients. The scipt makes use of sendmail. The scripts works for everything except gmail. When I go on gmail via my Web Browser, I can see the message with the attachment, but if I try to view or download the... (2 Replies)
Discussion started by: Wahooka
2 Replies

5. Shell Programming and Scripting

Sendmail Png Attachments

I use sendmail to send html emails, my script works perfect and sends email with plain text attachment. Now i need to attache png file to the email and this attachment part is not working. ( echo "From: $FROM" echo "To: $TO" echo "MIME-Version: 1.0" echo "Subject: $SUBJECT" echo... (4 Replies)
Discussion started by: posner
4 Replies

6. Shell Programming and Scripting

Sendmail gz Attachments

Hi All, I have a problem again with sendmail content type . I am trying to attach the gz file to the html email but couldnt figure out even after extensive google. Here is my code. ( echo "From: $FROM" echo "To: $MAILTO" echo... (3 Replies)
Discussion started by: posner
3 Replies

7. UNIX for Advanced & Expert Users

Sendmail questions, SCO 5.0.6 sendmail 8.11.0

I am running SCO 5.0.6 and using sendmail 8.11.0 and having issues with smtp authentication. When trying to send mail the following message will kick back. (reason: 530 5.7.1 Authentication required) 530 5.7.1 Authentication required Not sure what needs to be tweeked in sendmail.cf but I... (1 Reply)
Discussion started by: ziggy6
1 Replies

8. Shell Programming and Scripting

Mailing multiple PNG attachments using sendmail

Need assistance in using the below script and having multiple png file attachments in the same script . Your inputs are appreciated. I dont have uuencode , I use either mailx, sendmail, mpack . ( echo "to: samplemail@somewhere.com" echo "from: samplemail@elsewhere.com" echo "subject:... (2 Replies)
Discussion started by: ajayram_arya
2 Replies

9. Solaris

Clarifying sendmail configuration - sendmail-client offline

Hi all, I have read about sendmail running as 2 separate process. 1 as a MSP, and the other as the real daemon or MTA. In my current configuration, the sendmail-client is disabled. Both submit.cf and sendmail.cf are left as default untouch I do not specified any mailhost... (3 Replies)
Discussion started by: javanoob
3 Replies

10. Shell Programming and Scripting

Sendmail - Attachments & Subjects

Hi All, Not been around in a while. However I have been all over tinternet (google) for days looking for a solution. Where I work has decided to use Sendmail on our Linux and Unix estate for sending emails via scripts. So I am hoping to eventually get a working solution for Sendmail and not... (3 Replies)
Discussion started by: dakelly
3 Replies
Courriel::Builder(3pm)					User Contributed Perl Documentation				    Courriel::Builder(3pm)

NAME
Courriel::Builder - Build emails with sugar VERSION
version 0.29 SYNOPSIS
use Courriel::Builder; my $email = build_email( subject('An email for you'), from('joe@example.com'), to( 'jane@example.com', 'alice@example.com' ), header( 'X-Generator' => 'MyApp' ), plain_body($plain_text), html_body( $html, attach('path/to/image.jpg'), attach('path/to/other-image.jpg'), ), attach('path/to/spreadsheet.xls'), attach($file_content), ); DESCRIPTION
This module provides some sugar syntax for emails of all shapes sizes, from simple emails with a plain text body to emails with both plain and html bodies, html with attached images, etc. API
This module exports all of the following functions by default. It uses Sub::Exporter under the hood, which means you can easily import the functions with different names. See Sub::Exporter for details. build_email( ... ) This function returns a new Courriel object. It takes the results of all the other functions you call as input. It expects you to pass in a body of some sort, whether text, html, or both, and will throw an error if you don't. It will add Date and Message-ID headers to your email if you don't provide them, ensuring that the email is RFC-compliant. subject($subject) This sets the subject of the email. It expects a single string. You can pass an empty string, but not "undef". from($from) This sets the From header of the email. It expects a single string or Email::Address object. to($from) This sets the To header of the email. It expects a list of string and/or Email::Address objects. cc($from) This sets the Cc header of the email. It expects a list of string and/or Email::Address objects. bcc($from) This sets the Bcc header of the email. It expects a list of string and/or Email::Address objects. header( $name => $value ) This sets a header's value. You can call it as many times as you want, and you can call it more than once with the same header name to set multiple values for that header. plain_body( ... ) This defines a plain text body for the email. You can call it with a single argument, a scalar or reference to a scalar. This creates a text/plain part based on the content you provide in that argument. By default, the charset for the body is UTF-8 and the encoding is base64. You can also call this function with a hash of options. It accepts the following options: o content The content of the body. This can be a string or scalar reference. o charset The charset for the body. This defaults to UTF-8. o encoding The encoding for the body. This defaults to base64. Other valid values are quoted-printable, 7bit, and 8bit. It is strongly recommended that you let Courriel handle the transfer encoding for you. html_body( ... ) This accepts the same arguments as the "plain_body()" function. You can also pass in the results of one or more calls to the "attach()" function. If you pass in attachments, it creates a multipart/related email part, which lets you refer to images by the Content-ID using the "cid:" URL scheme. attach( ... ) This function creates an attachment for the email. In the simplest form, you can pass it a single argument, which should be a path to a file on disk. This file will be attached to the email. You can also pass a hash of options. The valid keys are: o file The file to attach to the email. You can also pass the content explicitly. o content The content of the attachment. This can be a string or scalar reference. o filename You can set the filename that will be used in the attachment's Content-Disposition header. If you pass a "file" parameter, that will be used when this isn't provided. If you pass as "content" parameter, then there will be no filename set for the attachment unless you pass a "filename" parameter as well. o mime_type You can explicitly set the mime type for the attachment. If you don't, this function will use File::LibMagic to try to figure out the mime type for the attachment. o content_id This will set the Content-ID header for the attachment. If you're creating a HTML body with "cid:" scheme URLs, you'll need to set this for each attachment that the HTML body refers to. The id will be wrapped in angle brackets ("<id-goes-here>") when set as a header. COOKBOOK
Some examples of how to build different types of emails. Simple Email With Plain Text Body my $email = build_email( subject('An email for you'), from('joe@example.com'), to( 'jane@example.com', 'alice@example.com' ), plain_body($plain_text), ); This creates an email with a single text/plain part. Simple Email With HTML Body my $email = build_email( subject('An email for you'), from('joe@example.com'), to( 'jane@example.com', 'alice@example.com' ), html_body($html_text), ); This creates an email with a single text/html part. Email With Both Plain and HTML Bodies my $email = build_email( subject('An email for you'), from('joe@example.com'), to( 'jane@example.com', 'alice@example.com' ), plain_body($plain_text), html_body($html_text), ); This creates an email with this structure: multipart/alternative | |-- text/plain (disposition = inline) |-- text/html (disposition = inline) Email With Both Plain and HTML Bodies and Inline Images my $email = build_email( subject('An email for you'), from('joe@example.com'), to( 'jane@example.com', 'alice@example.com' ), plain_body($plain_text), html_body( $html_text, attach( file => 'path/to/image1.jpg', cid => 'image1', ), attach( file => 'path/to/image2.jpg', cid => 'image2', ), ), ); This creates an email with this structure: multipart/alternative | |-- text/plain (disposition = inline) |-- multipart/related | |-- text/html (disposition = inline) |-- image/jpeg (disposition = attachment, Content-ID = image1) |-- image/jpeg (disposition = attachment, Content-ID = image2) Email With Both Plain and HTML Bodies and Attachments my $email = build_email( subject('An email for you'), from('joe@example.com'), to( 'jane@example.com', 'alice@example.com' ), plain_body($plain_text), html_body( $html_text, ), attach('path/to/spreadsheet.xls'), attach( content => $png_image_content ), ); multipart/mixed | |-- multipart/alternative | | | |-- text/plain (disposition = inline) | |-- text/html (disposition = inline) | |-- application/vnd.ms-excel (disposition = attachment) |-- image/png (disposition = attachment) AUTHOR
Dave Rolsky <autarch@urth.org> COPYRIGHT AND LICENSE
This software is Copyright (c) 2012 by Dave Rolsky. This is free software, licensed under: The Artistic License 2.0 (GPL Compatible) perl v5.14.2 2012-03-07 Courriel::Builder(3pm)
All times are GMT -4. The time now is 02:21 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy