Perl SMTP
IIS6 requires an Application Pool (like Sharepoint or Exchange) other than Default Application Pool for your Web or Virtual Directory for .Net mail sending via your webpage or else CDONTS library will throw Access Denied errors In Yer Face!
Well thanks to Perl's MIME-Lite and Net-SMTP you are likely to bypass this.
Code Snippet:
use MIME::Lite;use Net::SMTP;# This debug flag will print debugging code to your browser,# depending on its value# Set this to 1 to send debug code to your browser.# Set it to 0 to turn it off.my $DEBUG = 1;if($DEBUG){$| = 1;open(STDERR, ">&STDOUT");}# Set this variable to your smtp server name# my $ServerName = "YourSMTPServer";# Creat a new SMTP object#$smtp = Net::SMTP->new($ServerName, Debug => 1);# If you can't connect, don't proceed with the rest of the script#die "Couldn't connect to server" unless $smtp;### Adjust Sender & Recepient email addressmy $from_address = '';my $to_address = '';my $cc_address = '';my $mime_type = 'multipart/mixed';### Adjust subject and body messagemy $subject = '';my $message_body = "";### Adjust the file to attachmy $filename1 = '';my $recommended_filename1 = '';### Creat the initial text of the messagemy $mime_msg = MIME::Lite->new(From => $from_address,To => $to_address,Cc => $cc_address,Subject => $subject,Type => $mime_type,)or die "Error creating MIME body: $!\n";### Add the text message$mime_msg->attach(Type => 'TEXT',Data => $message_body) or die "Error adding the text message part: $!\n";### Attach the attachmnet file$mime_msg->attach(Type => 'application/txt',Path => $filename1,Filename => $recommended_filename1,Disposition => 'attachment',)or die "Error attaching test file: $!\n";my $message_body = $mime_msg->body_as_string();### Set this variable to your smtp server namemy $ServerName = "";### Creat a new SMTP object$smtp = Net::SMTP->new($ServerName, Debug => 1);### If you can't connect, don't proceed with the rest of the scriptdie "Couldn't connect to server" unless $smtp;MIME::Lite->send('smtp', $ServerName, Timeout=>60);$mime_msg->send;### Close the connection$smtp->quit();
If at first you fail, call it version 1.0
No comments:
Post a Comment