- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - OpenVMS
- >
- Attaching file(s) to sendmail in cgi
Operating System - OpenVMS
1752662
Members
5381
Online
108788
Solutions
Forums
Categories
Company
Local Language
юдл
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
юдл
back
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-01-2003 01:53 AM
тАО09-01-2003 01:53 AM
Attaching file(s) to sendmail in cgi
Hi, I'm in a CGI script and have got to the point where I want to send a mail using sendmail (which works btw), and I know which file(s) I want to send with the email (and have also uploaded them to Unix server).
The problem I have now is not knowing how to actually attach the file(s) to sendmail using the code I have below I can't get it to work, any ideas?
code:-----------------------------------------
open (MAIL, "|$mailProgram -f 'webserver' -F '$email_from' '$mailTo");
print "in mail loop so file is open";
print "\nsend to [$mailTo]";
print "\nfilename [$xmlfilename]";
print MAIL "To: $mailTo\n";
print MAIL "From: webserver\n";
print MAIL "Subject: Support Request Form Results\n\n";
# for each filename (later)
open (XMLFILE, "<$xmlfilename");
while ( )
{
print MAIL $_;
}
close (XMLFILE);
# now add attachments
print MAIL "uuencode $xmlfilename";
close (MAIL);
----------------------------------------------
I appreciate the test is only for one file at the moment, and for now, I'm sending to Microsoft Outlook, but only to test really, will be using pegasus mail on secure unix server so assume I'd have to duencode, appreciate the help
p.s. have already tried different variations of the uuencode but as yet, no success :(
The problem I have now is not knowing how to actually attach the file(s) to sendmail using the code I have below I can't get it to work, any ideas?
code:-----------------------------------------
open (MAIL, "|$mailProgram -f 'webserver' -F '$email_from' '$mailTo");
print "in mail loop so file is open";
print "\nsend to [$mailTo]";
print "\nfilename [$xmlfilename]";
print MAIL "To: $mailTo\n";
print MAIL "From: webserver\n";
print MAIL "Subject: Support Request Form Results\n\n";
# for each filename (later)
open (XMLFILE, "<$xmlfilename");
while (
{
print MAIL $_;
}
close (XMLFILE);
# now add attachments
print MAIL "uuencode $xmlfilename";
close (MAIL);
----------------------------------------------
I appreciate the test is only for one file at the moment, and for now, I'm sending to Microsoft Outlook, but only to test really, will be using pegasus mail on secure unix server so assume I'd have to duencode, appreciate the help
p.s. have already tried different variations of the uuencode but as yet, no success :(
Give me a firm spot on which to stand, and a long enough lever, and I shall Move the Earth, Oscar Wilde
One day, I will rule the world, Just one step at a time - Me, during hangover of 2003 ;)
One day, I will rule the world, Just one step at a time - Me, during hangover of 2003 ;)
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-01-2003 07:09 AM
тАО09-01-2003 07:09 AM
Re: Attaching file(s) to sendmail in cgi
Since you appear to be using Perl, there are much better ways to do this than opening a pipe to sendmail. I think the MIME::Lite extension is the easiest -- see the example below. BTW, if you are doing this on a UNIX server, why did you post the question in an OpenVMS forum? In any case, MIME::Lite works on any platform Perl works on.
#perl
use MIME::Lite;
MIME::Lite->send('smtp', "smtp.mydomain.com", Timeout=>60);
$file = shift @ARGV;
$recipients = shift @ARGV;
$subject = 'This message tests attachment reception [octet-stream].';
$message = "The attachment should be named $file\n";
if (&mail_file( $file, $recipients, $subject, $message ))
{
print "Mailed $file to $recipients.\n";
}
else
{
print "Error mailing $file to $recipients\n";
$error_count++;
}
exit;
#-------------------------------------------------------------------------------
# This routine actually mails the file as an attachment using base64 encoding.
sub mail_file
{
my ($path, $recipients, $subject, $message) = @_;
# Create a new message object.
my @recipient_list = split( /,\s*/, $recipients );
my $msg = new MIME::Lite
From =>$ENV{USER},
To =>\@recipient_list,
Subject =>$subject,
Type =>'TEXT',
Encoding=>'quoted-printable',
Data =>$message;
my $filename = $path;
if ($path)
{
# Attach a file to the message.
attach $msg Type =>'application/octet-stream',
Path =>$path,
Filename =>$filename,
Encoding =>'base64',
Disposition =>'attachment';
}
return $msg->send;
}
#perl
use MIME::Lite;
MIME::Lite->send('smtp', "smtp.mydomain.com", Timeout=>60);
$file = shift @ARGV;
$recipients = shift @ARGV;
$subject = 'This message tests attachment reception [octet-stream].';
$message = "The attachment should be named $file\n";
if (&mail_file( $file, $recipients, $subject, $message ))
{
print "Mailed $file to $recipients.\n";
}
else
{
print "Error mailing $file to $recipients\n";
$error_count++;
}
exit;
#-------------------------------------------------------------------------------
# This routine actually mails the file as an attachment using base64 encoding.
sub mail_file
{
my ($path, $recipients, $subject, $message) = @_;
# Create a new message object.
my @recipient_list = split( /,\s*/, $recipients );
my $msg = new MIME::Lite
From =>$ENV{USER},
To =>\@recipient_list,
Subject =>$subject,
Type =>'TEXT',
Encoding=>'quoted-printable',
Data =>$message;
my $filename = $path;
if ($path)
{
# Attach a file to the message.
attach $msg Type =>'application/octet-stream',
Path =>$path,
Filename =>$filename,
Encoding =>'base64',
Disposition =>'attachment';
}
return $msg->send;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-01-2003 09:36 AM
тАО09-01-2003 09:36 AM
Re: Attaching file(s) to sendmail in cgi
Hello,
I do almost perfectly agree with Craig ;-)
First you really would be better off in a Unix forum (OpenVMS does not use sendmail for SMTP services). E.g.
http://forums.itrc.hp.com/cm/CategoryHome/1,,150,00.html
might be appropriate (this is the hp-ux languages section).
Now, as to the solution to your problem, I quote the Perl motto "There is more than one way to do it", so I suggest the Mail::Sender Module rather than MIME::Lite since you do not have to bother about encoding the stuff yourself, the right form will be chossen automatically for you. I do use this module daily in a production environment to sent out both textual and binary file attachments.
Check http://search.cpan.org/author/JENDA/Mail-Sender-0.8.08/
for the module.
Greetings, Martin
I do almost perfectly agree with Craig ;-)
First you really would be better off in a Unix forum (OpenVMS does not use sendmail for SMTP services). E.g.
http://forums.itrc.hp.com/cm/CategoryHome/1,,150,00.html
might be appropriate (this is the hp-ux languages section).
Now, as to the solution to your problem, I quote the Perl motto "There is more than one way to do it", so I suggest the Mail::Sender Module rather than MIME::Lite since you do not have to bother about encoding the stuff yourself, the right form will be chossen automatically for you. I do use this module daily in a production environment to sent out both textual and binary file attachments.
Check http://search.cpan.org/author/JENDA/Mail-Sender-0.8.08/
for the module.
Greetings, Martin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-01-2003 12:08 AM
тАО10-01-2003 12:08 AM
Re: Attaching file(s) to sendmail in cgi
If your intention is only to send SMTP mail with file attachments from a Unix box, perhaps you would consider grabbing the following tool:
[Compaq C] Example-C,C++ SMTP Mail Message Sender With MIME File Attachments
available at the following URL:
http://h18000.www1.hp.com/support/asktima/communications/009F15E8-A8CE0B38-1C02A1.html
I tested the program on Tru64, HP-UX, Linux and Sun Solaris. Its use ought to be simple.
Hoping this can help you.
[Compaq C] Example-C,C++ SMTP Mail Message Sender With MIME File Attachments
available at the following URL:
http://h18000.www1.hp.com/support/asktima/communications/009F15E8-A8CE0B38-1C02A1.html
I tested the program on Tru64, HP-UX, Linux and Sun Solaris. Its use ought to be simple.
Hoping this can help you.
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
News and Events
Support
© Copyright 2024 Hewlett Packard Enterprise Development LP