Sponsored Content
Full Discussion: mailx help required
Top Forums Shell Programming and Scripting mailx help required Post 90232 by mschwage on Sunday 20th of November 2005 08:56:37 PM
Old 11-20-2005
Sending MIME messages, using Perl, with a ksh Script

By popular demand, here's how to send email using Perl with MIME attachments. I used to include a PDF attachment but my users are happier with plain text, so I haven't tested the $top->attach statement, but it's close. Caveat programmer.

Code:
#!/bin/ksh
# Usage:  $0 message attachment
# where message is a file containing an arbitrary text message and attachment
# is a gif file you want to attach.  If you don't want to use the latter feature, delete
# the line below that begins with \$top-attach
# Other filetypes are left to the reader to discern; do a google search for 
# perl mime::entity for more info

$eMAIL="recipient@example.com"
/opt/perl/5.8.0/bin/perl -e "use MIME::Entity; \$message=qx($1);
        \$top = MIME::Entity->build( \
        From => \"SomebodysName\\@donotreply.com\", \
        To => \"$eMAIL\", Subject => \"A nice picture\", \
        Data => \$message ); \
       \$top->attach(Path => \"$2\", Type => "image/gif", Encoding => "base64");\
        open MAIL, \"| /usr/lib/sendmail -t -oi -oem -v\" or die \"open: \$!\"; 
\$top->print(\\*MAIL); \
        close MAIL; \
        print \"\$message\\n------------------\\n\"; \
         \$top->print(); \
" > /tmp/out$$ &

# Here's some bonus code at no extra charge.  Sometimes sendmail must wait
# for a downstream server to reply.  This gives you some feedback.  notice that
# the perl command must match the perl command you called, above.
# So if you change your perl path, change it here too.  Hmm... I should probably
# put that in a shell variable, but you get what you pay for :-)
lines=1
cycles=30
while [ "$lines" -gt 0 -a $cycles -gt 0 ] ; do
        lines=`ps -j -o args | grep "/opt/perl/5.8.0/bin/perl -e use MIME::Entity" | grep -v grep | wc -l`
        if [ $lines -gt 0 ] ; then
                printf "."
                sleep 1
        else
                printf "\nMail sent. Wait a couple of minutes for it to arrive.\n"
                break
        fi
        if [ $cycles -eq 15 ] ; then
                printf "\nErgh. Mail seems slowish, still trying!\n";
                sleep 1
                printf "."
        fi
        cycles=`expr $cycles - 1`
done
if [ "$lines" -gt 0 ] ; then
        printf "\nMail is slow today. Still trying...  I'll check every minute.\n"
        printf "From now on, each hash symbol ( # ) represents 1 minute of time.\n"
fi
while [ "$lines" -gt 0 ] ; do
        lines=`ps -j -o args | grep "/opt/perl/5.8.0/bin/perl -e use MIME::Entity" | grep -v grep | wc -l`
        if [ $lines -gt 0 ] ; then
                sleep 60
                printf "#"
        else
                printf "\nMail sent. Wait a couple of minutes for it to arrive.\n"
        fi
done


Last edited by mschwage; 11-20-2005 at 09:58 PM.. Reason: coding error...
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Mailx

I am trying to write a shell script using the mailx command. My problem is that I want to send an email address in the CC: field. What option can I use with mailx to accomplish this. Any help would be very appreciative. (1 Reply)
Discussion started by: skammer
1 Replies

2. Shell Programming and Scripting

mailx to to Dl

Is there any way that I can mailx to a distribution list without having a $HOME/.mailrc file? We have a distribution list in Outlook for our group say group@something.com. I am trting to do echo "Something"|mailx -s "Subject" group@something.com it doesnt work Any ideas? Thanks (1 Reply)
Discussion started by: sm321
1 Replies

3. UNIX for Dummies Questions & Answers

mailx error message : mailx: NUL changed to @

If I use the "Mail" link instead of the "mail" link to ../mailx I get this error. Mail so-n-so @whatever.com mailx: NUL changed to @ Unknown command: "postmaster" The email still goes through but i get the error. If I use "mail" it goes thru without the error. Any ideas?? (2 Replies)
Discussion started by: BG_JrAdmin
2 Replies

4. Shell Programming and Scripting

mailx

Hi, Thanks in Advance !! I have a korn script which is used to mail the reports to the users. I'm using the mailx utility. The uid used for running the script is "cronman", so the mails recieved by users are id FROM:"cronman". Now i want to change the FROM address to another user name... (2 Replies)
Discussion started by: pradeep_desh
2 Replies

5. Shell Programming and Scripting

mailX

I would like to get a solution .. how can i attach more than one file to a mail using mailx yep........ sure if test.dat is the file cat test.dat|uuencode test.dat|mailx -s "subject" mailid can be used for attaching test.dat how can we attach test1.dat and test2.dat (4 Replies)
Discussion started by: anumkoshy
4 Replies

6. UNIX for Advanced & Expert Users

mailx

We are using mailx to send email alerts. On occasions, it is updating our Distribution list with the mesage content. The following is the relevant portion of the script :- MAILGROUP=`more $MDS/feeds/alerts/distribution.lst` export MAILGROUP echo " " | mailx -s "MDS Alert - Refresh Complete"... (6 Replies)
Discussion started by: Paul Byrne
6 Replies

7. Ubuntu

mailx

hi, I am working on a ksh script and i want to be able to send a email using mailx. if ] || ] then echo "send email" mailx -s "Subject goes here" <email address>; fi thats what i have so far, in place of "<email address>" I have my actualy email address and I want to add a body with... (6 Replies)
Discussion started by: mike509123
6 Replies

8. Shell Programming and Scripting

Getting required fields from a test file in required fromat in unix

My data is something like shown below. date1 date2 aaa bbbb ccccc date3 date4 dddd eeeeeee ffffffffff ggggg hh I want the output like this date1date2 aaa eeeeee I serached in the forum but didn't find the exact matching solution. Please help. (7 Replies)
Discussion started by: rdhanek
7 Replies

9. Shell Programming and Scripting

Mailx: How to send a attachment using mailx command

Hi All, Can anyone please provide the command for sending an mail with attachment using mailx command. Thanks in Advance :) Regards, Siram. (3 Replies)
Discussion started by: Sriram.Vedula53
3 Replies

10. Linux

Mailx

We have configured mailx Linux server. When send mail from Linux server it is not going How to trouble shoot the root cause step by step (3 Replies)
Discussion started by: pmsuper
3 Replies
GLFRAMEBUFFERRENDERB(3G)					    OpenGL 3.3						  GLFRAMEBUFFERRENDERB(3G)

NAME
glFramebufferRenderbuffer - attach a renderbuffer as a logical buffer to the currently bound framebuffer object C SPECIFICATION
GLsync glFramebufferRenderbuffer(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer); PARAMETERS
target Specifies the framebuffer target. target must be GL_DRAW_FRAMEBUFFER, GL_READ_FRAMEBUFFER, or GL_FRAMEBUFFER. GL_FRAMEBUFFER is equivalent to GL_DRAW_FRAMEBUFFER. attachment Specifies the attachment point of the framebuffer. renderbuffertarget Specifies the renderbuffer target and must be GL_RENDERBUFFER. renderbuffer Specifies the name of an existing renderbuffer object of type renderbuffertarget to attach. DESCRIPTION
glFramebufferRenderbuffer attaches a renderbuffer as one of the logical buffers of the currently bound framebuffer object. renderbuffer is the name of the renderbuffer object to attach and must be either zero, or the name of an existing renderbuffer object of type renderbuffertarget. If renderbuffer is not zero and if glFramebufferRenderbuffer is successful, then the renderbuffer name renderbuffer will be used as the logical buffer identified by attachment of the framebuffer currently bound to target. The value of GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE for the specified attachment point is set to GL_RENDERBUFFER and the value of GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME is set to renderbuffer. All other state values of the attachment point specified by attachment are set to their default values. No change is made to the state of the renderbuuffer object and any previous attachment to the attachment logical buffer of the framebuffer target is broken. Calling glFramebufferRenderbuffer with the renderbuffer name zero will detach the image, if any, identified by attachment, in the framebuffer currently bound to target. All state values of the attachment point specified by attachment in the object bound to target are set to their default values. Setting attachment to the value GL_DEPTH_STENCIL_ATTACHMENT is a special case causing both the depth and stencil attachments of the framebuffer object to be set to renderbuffer, which should have the base internal format GL_DEPTH_STENCIL. ERRORS
GL_INVALID_ENUM is generated if target is not one of the accepted tokens. GL_INVALID_ENUM is generated if renderbuffertarget is not GL_RENDERBUFFER. GL_INVALID_OPERATION is generated if zero is bound to target. SEE ALSO
glGenFramebuffers(), glBindFramebuffer(), glGenRenderbuffers(), glFramebufferTexture(), glFramebufferTexture1D(), glFramebufferTexture2D(), glFramebufferTexture3D() COPYRIGHT
Copyright (C) 2010 Khronos Group. This material may be distributed subject to the terms and conditions set forth in the Open Publication License, v 1.0, 8 June 1999. http://opencontent.org/openpub/. OpenGL 3.3 03/08/2011 GLFRAMEBUFFERRENDERB(3G)
All times are GMT -4. The time now is 08:11 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy