For Programmers: Free Programming Magazines  


Home > Archive > PERL CGI Beginners > May 2007 > Tweeking a sendmail routine.









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Tweeking a sendmail routine.
Greg Schiedler

2007-03-22, 6:55 pm

I know enough Perl to be dangerous!

I have a form that sends out several different confirmations depending on
who the receipient is.

One particular E-mail I need to be in html format so I can put it into a
specific format. I added a couple of lines to the sendmail routine I was
using and it fixed my E-mail problem but created a problem with my fax
gateway copy.

#1 gets sent the Joe Enduser plain E-mail(Can be html my tw forced html)
#2 gets sent to the Office HTML Format.
#3 Fax gateway (Plain E-mail).

Fax gateway is in the US Telephone format ie. 1xxxyyyzzzz@efaxsend.com

I thought about adding an if statment but it looks like if I added an
if/else to my twed else statement the receipient info has already been
sent....

Greg :-)


file: sendmail.pl
<snip>
# Give the server the message header

print SMTP "DATA$CRLF";
sysread(SMTP, $_, 1024);
if (!/[^0-9]*354/) { $Error_Message = $_; return(6) }
print SMTP "To: @to$CRLF";
print SMTP "From: $from$CRLF";
print SMTP "CC: @cc$CRLF" if $cc;
print SMTP "Subject: $subject$CRLF";

# If there are mime files to attach, we need special headers.

if ($mime_id) {
print SMTP "x-sender: $from$CRLF";
print SMTP "x-mailer: CGI/Perl Cookbook$CRLF";
print SMTP "Mime-Version: 1.0$CRLF";
print SMTP "Content-Type: multipart/mixed;
boundary=\"$mime_id\"$CRLF$CRLF";
print SMTP "--$mime_id$CRLF";
print SMTP "Content-Type: text/plain;
charset=\"US-ASCII\"$CRLF$CRLF";
}
# Greg @ Limo.Net 01/24/2007
# Added two header lines for force HTML output.
# else { print SMTP $CRLF }
#
else {
print SMTP "Mime-Version: 1.0$CRLF";
print SMTP "Content-Type: text/html;
charset=\"ISO-8859-1\"$CRLF$CRLF";
}
# End Greg @ Limo.Net 01/24/2007

# Output the message body.

if ($body) {
if (!($body =~ /^[\\\/:]/) && ($body =~ /\s/)) { print SMTP $body }
elsif (-e $body && -T $body) { &parse_template($body, *SMTP) }
}
print SMTP $CRLF;

# Attach each file.

for ($i = 0; $i < @ATTACH_FILES; ++$i) {
$attach_file = $ATTACH_FILES[$i];
$encoding = $ENCODING[$i];

# Split the filename by directories. / for unix, \ for dos, : for
mac
</snip>


Scanned for Virus by http://Barracuda.Limo.Net
Wiggins d'Anconia

2007-03-25, 9:55 pm

Greg Schiedler wrote:
> I know enough Perl to be dangerous!
>
> I have a form that sends out several different confirmations depending on
> who the receipient is.
>
> One particular E-mail I need to be in html format so I can put it into a
> specific format. I added a couple of lines to the sendmail routine I was
> using and it fixed my E-mail problem but created a problem with my fax
> gateway copy.
>
> #1 gets sent the Joe Enduser plain E-mail(Can be html my tw forced html)
> #2 gets sent to the Office HTML Format.
> #3 Fax gateway (Plain E-mail).
>
> Fax gateway is in the US Telephone format ie. 1xxxyyyzzzz@efaxsend.com
>
> I thought about adding an if statment but it looks like if I added an
> if/else to my twed else statement the receipient info has already been
> sent....
>
> Greg :-)
>


Best suggestion would be to switch to using a module. MIME::Lite for
instance but there a lot that will work. Check CPAN. Mail while it seems
simple is incredibly complex, re-inventing the wheel, especially with
such strict requirements is going to be time consuming.

http://danconia.org

>
> file: sendmail.pl
> <snip>
> # Give the server the message header
>
> print SMTP "DATA$CRLF";
> sysread(SMTP, $_, 1024);
> if (!/[^0-9]*354/) { $Error_Message = $_; return(6) }
> print SMTP "To: @to$CRLF";
> print SMTP "From: $from$CRLF";
> print SMTP "CC: @cc$CRLF" if $cc;
> print SMTP "Subject: $subject$CRLF";
>
> # If there are mime files to attach, we need special headers.
>
> if ($mime_id) {
> print SMTP "x-sender: $from$CRLF";
> print SMTP "x-mailer: CGI/Perl Cookbook$CRLF";
> print SMTP "Mime-Version: 1.0$CRLF";
> print SMTP "Content-Type: multipart/mixed;
> boundary=\"$mime_id\"$CRLF$CRLF";
> print SMTP "--$mime_id$CRLF";
> print SMTP "Content-Type: text/plain;
> charset=\"US-ASCII\"$CRLF$CRLF";
> }
> # Greg @ Limo.Net 01/24/2007
> # Added two header lines for force HTML output.
> # else { print SMTP $CRLF }
> #
> else {
> print SMTP "Mime-Version: 1.0$CRLF";
> print SMTP "Content-Type: text/html;
> charset=\"ISO-8859-1\"$CRLF$CRLF";
> }
> # End Greg @ Limo.Net 01/24/2007
>
> # Output the message body.
>
> if ($body) {
> if (!($body =~ /^[\\\/:]/) && ($body =~ /\s/)) { print SMTP $body }
> elsif (-e $body && -T $body) { &parse_template($body, *SMTP) }
> }
> print SMTP $CRLF;
>
> # Attach each file.
>
> for ($i = 0; $i < @ATTACH_FILES; ++$i) {
> $attach_file = $ATTACH_FILES[$i];
> $encoding = $ENCODING[$i];
>
> # Split the filename by directories. / for unix, \ for dos, : for
> mac
> </snip>
>
>
> Scanned for Virus by http://Barracuda.Limo.Net
>


Robert Hicks

2007-03-26, 9:55 pm

Wiggins d'Anconia wrote:
> Greg Schiedler wrote:
>
> Best suggestion would be to switch to using a module. MIME::Lite for
> instance but there a lot that will work. Check CPAN. Mail while it seems
> simple is incredibly complex, re-inventing the wheel, especially with
> such strict requirements is going to be time consuming.
>


I like MIME::Lite and use it in anything of this sort. : )

Robert
Cheungy

2007-05-04, 7:56 pm

Anjelina Jolie doing it!
http://Angelina-Jolie-doing-it.info...hp?movie=148803
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com