cancel
Showing results for 
Search instead for 
Did you mean: 

sendmail program

abhay_6
Occasional Contributor

sendmail program

I am looking for a simple SMTP based program to send mail from a HP-UX machine.

It should take the following as command line arguments :

a. recepient's address
b. subject
c. mail text
d. filename - optional (as attachment)

any help will be appreciated.

7 REPLIES
abhay_6
Occasional Contributor

Re: sendmail program

The subject is misleading. I am looking for SMTP and not sendmail based program.
Zafar A. Mohammed_1
Trusted Contributor
abhay_6
Occasional Contributor

Re: sendmail program

I am looking for a SMTP based program. To my knowledge, mailx uses sendmail.
Paddy_1
Valued Contributor

Re: sendmail program

I have a perl script which does this but I dont have the option of file attachments.

I had to use this as cgi for web messaging.

I know of a Java program which uses a nice interface and implements SMTP too.

Let me know what will do.
The sufficiency of my merit is to know that my merit is NOT sufficient
abhay_6
Occasional Contributor

Re: sendmail program

Paddy,
If you have code for the perl or cgi program, can you forward it to me pl.
abhay
Paddy_1
Valued Contributor

Re: sendmail program

Here is the code to replace sendmail.this is aimplemented as sub routine so that you can call it in a perlscript
---------------------------
sub sendmail {
my $rh_Stuff = $_[0];
my $rc = 1;

my ($iaddr, $paddr, $proto, $a, $i);
my $Subject = $$rh_Stuff{'Subject'} || "Default Subject";
my $From = $$rh_Stuff{'From'} || "$$rh_Stuff{'DefaultFrom'}";
my $Server = $$rh_Stuff{'Server'} || "";
my $RetAddr = $From;
if ($$rh_Stuff{'RealName'}) {
$RetAddr = '"'.$$rh_Stuff{'RealName'}.'"'." <$From>";
}
$rc = &error("No recipient!") unless $$rh_Stuff{'To'};
my @TO = split(/,\s*/,$$rh_Stuff{'To'});

$Port = $$rh_Stuff{'Port'};
$Port ||= 25;
$Port = getservbyname($Port,'tcp') if $Port =~ /\D/;
$rc = &error("Port not valid.") unless $Port;

$iaddr = inet_aton($Server);
$rc = &error("Can not resolve hostname $Server") unless $iaddr;

$paddr = sockaddr_in($Port, $iaddr);
$proto = getprotobyname('tcp');
my $ipstring = inet_ntoa((unpack_sockaddr_in($paddr))[1]);

socket(S, PF_INET, SOCK_STREAM, $proto) || &error("socket call failed: $!");
connect(S, $paddr) || &error("Unable to connect to $ipstring on port $port: $! (possibly no route to host or connection refused by host)");

select(S); $| = 1; select(STDOUT);

&PrintHTMLWeb("Connection made to $$rh_Stuff{'Server'}:$Port\n") if $SHOW_SMTP_DEBUG;

# session is initiated

$a = &ReadMultiLineSMTP();
$rc = &error("SMTP error: $a") if $a !~ /^2/;

&WriteSocket("HELO localhost$CRLF");

$a = &ReadMultiLineSMTP();

$rc = &error("SMTP error: $a") if $a !~ /^2/;

&WriteSocket("MAIL FROM:$From$CRLF");

$a = &ReadMultiLineSMTP();

$rc = &error("SMTP error: $a") if $a !~ /^2/;

foreach $i(@TO) {
&WriteSocket("RCPT TO:<$i>$CRLF");
$a = &ReadMultiLineSMTP();
$rc = &error("SMTP error: $a") if $a !~ /^2/;
}

# send message body
&WriteSocket("DATA$CRLF");
$a = &ReadMultiLineSMTP();
$rc = &error("SMTP error: $a") if $a !~ /^3/;

&WriteSocket("From: $RetAddr$CRLF");
&WriteSocket("To: $TO[0]");
for ($i = 1; $i < @TO; $i++) {
&WriteSocket(",$TO[$i]");
}
&WriteSocket("$CRLF");
&WriteSocket("Subject: $Subject$CRLF");
&WriteSocket("Reply-To: $From$CRLF");
&WriteSocket("X-Mailer: Your Mailer$CRLF");
&WriteSocket("X-Referer: $ENV{'REMOTE_HOST'}$CRLF");

&WriteSocket("$CRLF");

&WriteSocket("$$rh_Stuff{'Message'}$CRLF");

&WriteSocket("$CRLF.$CRLF");

$a = &ReadMultiLineSMTP();
&WriteSocket("QUIT$CRLF");

return $rc;
}
-----------------------------
The sufficiency of my merit is to know that my merit is NOT sufficient
Paddy_1
Valued Contributor

Re: sendmail program

sorry! I forgot to include how to call it.
Here's how you call it.
----------------------------
&sendmail( { 'DefaultFrom' => "$DefaultFrom",
'Server' => "$MailServer",
'From' => "$Data{'From'}",
'RealName' => "$Data{'RealName'}",
'To' => "$To",
'Subject' => "$Data{'Subject'}",
'Message' => "$TEXT",
}
);


---------------------------
I am assuming that you are taking your mail document and storing the data in a hash_table.
something like $Data{'To'} stores the to address and subject and so on..
Let me know if you need something else
The sufficiency of my merit is to know that my merit is NOT sufficient