attachment displaying full path when emailed using perl script - perl

My perl script emails attachment which displays full path (/abc/xyz/report.xls) in outlook email client but not in lotus notes email client.
environment: 2010 Outlook on windows 7 OS.
How do I make sure path is not displayed in the attachment?
Code Snippet:
&sendEmail(#subject, #message, $exception_report_xls);
sub sendEmail
{
my $subject = "#subject";
my $distlist = 'ayc#abc.com';
my $message ="\n\n\n#message \n";
my $send = system("\(echo \"$message\" ; uuencode \"$exception_report_xls\" \"$exception_report_xls\"\) | mailx -s \"$subject\" \"$distlist\"");
}
Appreciate any resonse!
Ramya.

You are writing the full path and filename of the XLS file in the source of the message. So, some mail clients will display the full path.
If you are wedded to using (antiquated) UUENCODE, try it this way instead:
sub Send_Email_UUENCODE {
local($to, $from, $subj, $message, $attach) = #_;
local($i,$filename,$cmd,$att,$mailprog);
$i=length($attach)-1;
while( (substr($attach,$i,1) cmp '/')!=0 && $i>0) {$i--;}
$filename=substr($attach,$i+1,length($attach)-$i-1);
if ($attach) {
$cmd="uuencode " . $attach . ' ' . $filename;
$att=`$cmd`;
}
$mailprog = "/usr/sbin/sendmail -f " . $from;
open (MAIL, "|$mailprog $to") || die "Can't open $mailprog!\n";
print MAIL "To: $to\n";
print MAIL "From: $from\n";
print MAIL "Subject: $subj\n";
print MAIL "$message\n";
if ($attach) {
print MAIL "$att\n";
}
close (MAIL);
}
But, better might be to use MIME encoding instead of UUENCODE.

Related

Sending email using perl with sendmail

I am trying to send email using sendmail in perl. Email is sent but the content which I send as Subject gets added to 'To:' in the email. For example, if from address is from#gmail.com, To address is to#gmail.com and subject is "test subject". I get the email with Reply-to: field as from#gmail.com,"Subject:test.email","To:to"#gmail.com,"Content-type:text/plain"
Here is my code:
open(SENDMAIL, "|/usr/lib/sendmail -oi -t '$to_email' -f '$from_email'") || ($error_message .= "<P>Unable to open email process.</P>");
print SENDMAIL $reply_to;
print SENDMAIL $subject;
print SENDMAIL $send_to;
print SENDMAIL "Content-type: text/plain\n\n";
print SENDMAIL $content;
close(SENDMAIL);
And if I remove $reply_to and $send_to lines, the email comes with from: field
as Apache server.
Any help would be appreciated. I do not want to use any other library like Email::MIME since it doesn't exist on my system.
I am not sure what is wrong with what you show, but here is some working code
my ($header, $From, $To, $Cc, $ReplyTo, $Subject);
$From = "From: $from";
$To = "To: $to";
$Cc = "Cc: $cc_addresses";
$ReplyTo = "Reply-To: $replyto";
$Subject = "Subject: $subj";
# Form the header. The fields always submitted:
$header = join("\n", $From, $To, $ReplyTo, $Subject, '');
# Optional fields
$header .= "$Cc\n" if $cc_addresses;
open(SENDMAIL, "|/usr/sbin/sendmail -oi -t")
or carp "Can't fork for sendmail: $!\n";
say SENDMAIL "$header\n$msg_cont";
close(SENDMAIL);
Note. There is my $cc_addresses = ''; earlier, which then (possibly) gets built up.

How to make a single variable perform as a script

I've been using this module to write simple scripts to log into a server and perform a single command.
use Net::SSH qw(sshopen2);
use strict;
my $user = "username";
my $host = "hostname";
my $cmd = "command";
sshopen2("$user\#$host", *READER, *WRITER, "$cmd") || die "ssh: $!";
while (<READER>) {
chomp();
print "$_\n";
}
close(READER);
close(WRITER);
But I need the $cmd variable to perform this operation below.
my $dir = "/srv/archive/$date";
my $time = `date`;
open my $LOG, '>>', '/srv/archive/test.log';
if ( ! -e $dir )
{
my $to = 'xxxxx#xxxxx.com';
my $from = 'node0#example.com';
my $subject = '**DROP FILE TEST ALERT**';
my $message = "Please check if the $date directory exists";
open(MAIL, "|/usr/sbin/sendmail -t");
# Email Header
print MAIL "To: $to\n";
print MAIL "From: $from\n";
print MAIL "Subject: $subject\n\n";
# # Email Body
print MAIL $message;
close(MAIL);
print "Email Sent Successfully\n" ;
print $LOG "$time (Bad)";
}
else
{
print "The directory exists!\n";
print $LOG "$time (Good)\n";
}
The reason why I'm using this is because I am not allowed to execute a script inside the server. Thanks in advance.
Manually printing headers to sendmail is no longer a good way to send email. Modern email contains multiple, complicated guards against spammers. Most mail servers and clients will reject your mail as spam.
There's no reason the email has to be sent on the remote server. Instead, send the mail via a normal SMTP connection. Consider using Email::Sender instead.
If you absolutely must send the mail from the remote server, write a script to do it (also using Email::Sender) and invoke that script.

How is it possible to use a special character (a star) in the "from" field using Perl's sendmail

I am using Perl's SENDMAIL to receive email from my website:
open(SENDMAIL, "|$sendmail") or die "Cannot open $sendmail: $!";
print SENDMAIL "From: $from\n";
print SENDMAIL "Subject: $subject\n";
print SENDMAIL "To: $to\n";
print SENDMAIL "Content-type: text/plain\n\n";
print SENDMAIL $message;
close(SENDMAIL);
And I would like to modify the $from variable to be something like this:
$from = "★ David Jones <david.jones#oozicle.com>"
What happens right now is that I just see the ampersand etc., and the star is not shown.
I know that it is possible to use special characters because I receive spam containing them.
Is it possible to do this using SENDMAIL?
use Encode qw( encode );
my $name = "\x{2605} David Jones";
my $addr = 'david.jones#oozicle.com';
my $from_header = encode('MIME-Header', $name) . ' <' . $addr . '>';

not able to send bulkmail through sendmail

I am trying to send e-mail to a group but not being able to send
catch is my script is sending e-mail to individual id, but not group.
Googled it but not much helpful.
For sending to bulk users i don't want to use alias, some restrictions.
Please Advice
#!/usr/bin/perl
#!/usr/sbin/sendmail
$to = 'xxxx#yyy.something.com,';
$from = 'abc#something.com';
$subject = 'Subject';
#$message = 'This is test mail';
open(MAIL, "|/usr/sbin/sendmail -t");
# Email Header
print MAIL "To: $to\n";
print MAIL "From: $from\n";
print MAIL "Subject: $subject\n\n";
# Email Body
print MAIL "print something";
close(MAIL);
#print "Email Sent Successfully\n
Pass list of recipients as sendmail command line arguments - AFAIR it should work on Linuxes for a few hundredth recipients.
#!/usr/bin/perl
use strict;
use warnings;
my #to = ('xxxx#yyy.something.com','yyyy#xxx.something.com');
my $from = 'abc#something.com';
my $subject = 'Subject';
#my $child_pid = open(MAIL, "|-") // die "can't fork: $!";
defined( my $child_pid = open(MAIL, "|-")) || die "can't fork: $!";
if( $child_pid == 0 ) {
exec( '/usr/sbin/sendmail', '-i', '--', #to) || die "can't exec: $!";
}
# Email Headers & Body
print MAIL << "END" ;
From: $from
Subject: $subject
print something
END
close(MAIL) && print "Email Sent Successfully\n";

Sendmail Format

Not sure where I am doing wrong, but when I am putting $hostname variable within "$from" variable, sendmail is not printing anything within subject line, else it works fine.
I want to put "from" as noreply#hostname.
Here is the code :
my $f="test.txt";
my $h=`hostname`;
if ( -s "$f" ) {
my $to='user#example.com';
my $from= "noreply\#$h";
my $subject='Test Error';
open(MAIL, "|/usr/sbin/sendmail -t");
## Mail Header
print MAIL "To: $to\n";
print MAIL "From: $from\n";
print MAIL "Subject: $subject\n\n";
## Mail Body
print MAIL "Test Body\n";
close(MAIL);
}
Your $h has a trailing newline on the end of it.
Add a chomp to fix it:
my $h=`hostname`;
chomp $h;
Also, it's a good idea to use lexical variables instead of global filehandles, and the three-argument form of open:
open my $mail, '|-', '/usr/sbin/sendmail -t';
## Mail Header
print $mail "To: $to\n";
print $mail "From: $from\n";
print $mail "Subject: $subject\n\n";
## Mail Body
print $mail "Test Body\n";
close $mail;