Sending Mail Without Use of Module or Sendmail

G

gratemyl

Hi!

I would like to send mail using perl without using a module or
sendmail.

I don't want to use sendmail to ensure portability to Win32 - without
the need to download sendail first.

I don't want to use modules such as Net::DNS to lookup the MX server -
those were the requirements given to me.

- I can use only built-in features of perl 5.8.7.
- I need to communicate with the official MX server, so i need to look
that up somehow.
- I cannot depend on any external script which cannot be built-in to
my script. Neither can i call a web-service of any kind.

Thanks in advance,

Yours,

Gratemyl
 
M

MikeGee

I get the impression that you a required to supply one perl file that
"just works." If that is the case, rather than excluding the use of
modules, you can include them in your file directly. See below:

-- start of your script --

package Net::SMTP;

# the rest of the contents of Net::SMTP

package Some::Other::Module::You::Need;

# contents

package main;

#your program, using the above modules

-- end of your script --
 
G

gratemyl

Thanks for the speedy reply, but that is not the case. I have been
asked to provide a script which simply works without the use of ANY
module (even "strict" or "warnings").

I don't totally understand the need for that, but I have been told it
HAS to be that way...

Thanks again for the fast reply, but I was looking for something
else...

Thanks again in advance,

Yours,

Gratemyl
 
B

brian d foy

Thanks for the speedy reply, but that is not the case. I have been
asked to provide a script which simply works without the use of ANY
module (even "strict" or "warnings").

Walk away. Find something else to do because down that path lies
frustration and too little money.

Either that, or make the case that you should be able to use the
modules which come with Perl. Most the the modules you need will
already be installed.

The Module::CoreList module can list all of those modules for
you for the last several versions of Perl.
 
G

gratemyl

I am well aware of the modules available to me, but thanks anyway.

This is a school project, so I cannot simply walk away, unluckily.

I cannot alter the requirements, I already discussed this with my
subject teacher. He has given me permission and suggested obtaining
information from the internet - which as you can see I am doing.

There will not be an issue of monetary resources, since I have to
supply only source code, NOTHING else.

Thanks again for the speedy reply, but again this is not what I was
looking for.

Yours,

Gratemyl
 
A

axel

brian d foy said:
Walk away. Find something else to do because down that path lies
frustration and too little money.
Either that, or make the case that you should be able to use the
modules which come with Perl. Most the the modules you need will
already be installed.

It sounds like a homework exercise to me.

Axel
 
H

Henry Law

Hi!

I would like to send mail using perl without using a module or
sendmail.

I don't want to use sendmail to ensure portability to Win32 - without
the need to download sendail first.

I don't want to use modules such as Net::DNS to lookup the MX server -
those were the requirements given to me.

- I can use only built-in features of perl 5.8.7.
- I need to communicate with the official MX server, so i need to look
that up somehow.
- I cannot depend on any external script which cannot be built-in to
my script. Neither can i call a web-service of any kind.

You'll have to use the basic socket functions to talk directly to the
servers you want to use - DNS, SMTP and so on, and then implement the
portions of the DNS and SMTP protocols which you need. But watch the
incompatibilities between UNIX and ActiveState Perl, as described in the
"Windows Specific" section of the ActiveState documentation. But wait
.... the whole purpose of this was WIN32 compatibility ...

Sounds a pretty pointless task to me - or is it some kind of "trial by
ordeal"? Will you tell us what secret and arcane society you may join
when you've completed it? Or maybe there's a fair damsel to be won ...
 
G

gratemyl

The whole purpose was not Win32 compat.

It is not a "trial". It is a homework exercise - assigned individually
to each student, and I got this...

Indeed, I have realised, before asking, that I will have to talk
directly to the DNS server. But I was looking for some perl-specific
sample code on the DNS query - the rest is easy for me.

I do have permission by the subject supervisor to obtain THIS SEPECIFIC
help from a forum or newsgroup of some kind, I contacted my supervisor
abou that.

The only piece of code which I would need is to talk directly to the
DNS server.

Thanks again in advance,

Yours,

Gratemyl
 
T

Tintin

The whole purpose was not Win32 compat.

It is not a "trial". It is a homework exercise - assigned individually
to each student, and I got this...

Indeed, I have realised, before asking, that I will have to talk
directly to the DNS server. But I was looking for some perl-specific
sample code on the DNS query - the rest is easy for me.

You don't need any interaction with a DNS server, you need to talk to a SMTP
server, which could be running on your localhost or some other server.

If you're no allowed to use modules, then read up on:

perldoc Socket

Also, have a look through the code of Mail::Sendmail, which despite its
misleading name, uses sockets to talk to an SMTP server.
 
F

Fayland Lam

The whole purpose was not Win32 compat.

It is not a "trial". It is a homework exercise - assigned individually
to each student, and I got this...

Indeed, I have realised, before asking, that I will have to talk
directly to the DNS server. But I was looking for some perl-specific
sample code on the DNS query - the rest is easy for me.

I do have permission by the subject supervisor to obtain THIS SEPECIFIC
help from a forum or newsgroup of some kind, I contacted my supervisor
abou that.

The only piece of code which I would need is to talk directly to the
DNS server.

as follows are some dirty code from an old Chinese BBS script:

sub smtpmail {
if ($main::loadsocketmo ne 1) { eval("use Socket;");
$main::loadsocketmo = 1; }
my ($address, $from, $replyaddr, $subject, $body, $extra) = @_;
$body = Base64encode($body);
$subject = mimeencode($subject);
my $tempname = mimeencode($main::boardname);

my ($name, $aliases, $proto, $type, $len, $thataddr);
my @to = split(/, /, $address);
foreach my $i (@to) {

my $AF_INET = 2;
my $SOCK_STREAM = 1;
my $SOCKADDR = 'S n a4 x8';

($name, $aliases, $proto) = getprotobyname('tcp');
($name, $aliases, $type, $len, $thataddr) =
gethostbyname($main::SMTP_SERVER);
my $this = pack($SOCKADDR, $AF_INET, 0);
my $that = pack($SOCKADDR, $AF_INET, $main::SMTP_PORT, $thataddr);

socket(S, $AF_INET, $SOCK_STREAM, $proto);
bind(S, $this);
connect(S, $that);

select(S);
$| = 1;
select(STDOUT);
my $a = <S>;
if ($a !~ /^2/) {
close(S);
undef $|;
return $a;
}

if ($extra eq "no") {
print S "HELO localhost\r\n";
$a = <S>;
} else {
print S "EHLO localhost\r\n";
$a = <S>;
print S "AUTH LOGIN\r\n";
$a = <S>;
my $encode_smtpuser = &Base64encode($main::SMTPUSER);
print S "$encode_smtpuser\r\n";
$a = <S>;
my $encode_smtppass = &Base64encode($main::SMTPPASS);
print S "$encode_smtppass\r\n";
$a = <S>;
return $a if ($a =~ /fail/i);
}

print S "MAIL FROM: <$from>\r\n";
$a = <S>;
print S "RCPT TO: <$i>\r\n";
$a = <S>;

print S "DATA\r\n";
$a = <S>;
print S "From: $tempname<$from>\r\n";
print S "To: $i\r\n";
print S "Subject: $subject\r\n";
print S "Reply-To: $tempname<$replyaddr>\r\n" if ($replyaddr);
print S "X-Mailer: LeoBBS eSmtp Mail Sender\r\n";
print S "Content-Type: text/html; charset=gb2312\r\n";
print S "Content-Transfer-Encoding: base64\r\n\r\n";
print S "$body\r\n";
print S "\r\n\r\n";
print S ".\r\n";
$a = <S>;

print S "QUIT\r\n";
$a = <S>;
close(S);
undef $|;
}
return 1;
}

sub mimeencode {
my $str = shift;
return '=?gb2312?B?'.Base64encode($str).'?=';
}

sub Base64encode {
my $res = pack("u", $_[0]);
$res =~ s/^.//mg;
$res =~ s/\n//g;
$res =~ tr|` -_|AA-Za-z0-9+/|;
my $padding = (3 - length($_[0]) % 3) % 3;
$res =~ s/.{$padding}$/'=' x $padding/e if $padding;
return $res;
}

this may help. use it at your own risk. ;-)
 
G

Gratemyl

I do not have access to any local or other SMTP server for my sender.
Without installation of specification of an SMTP server, my script
should be able to send mail - by directly contacting the SMTP server
for the receipient's domain.

Thanks anyway,

Yours,

Gratemyl

BTW: I am aware of how to use the raw socket calls in perl, but DNS
seems to be a complex protocol to learn...
 
G

Gratemyl

Thanks for the reply, but I was not specifically looking for this code.
Still, I am very thankful for this code, as it could provide the base
of my MIME encoding code (I have to include attachments, etc.)

So thanks for the code,

Yours,

Gratemyl
 
T

Tintin

Gratemyl said:
I do not have access to any local or other SMTP server for my sender.
Without installation of specification of an SMTP server, my script
should be able to send mail - by directly contacting the SMTP server
for the receipient's domain.

Without an SMTP it will be impossible to send mail.
BTW: I am aware of how to use the raw socket calls in perl, but DNS
seems to be a complex protocol to learn...

Don't worry about DNS. For your purposes, you shouldn't need to worry about
it.
 
G

Gratemyl

Tintin said:
Without an SMTP it will be impossible to send mail.
I meant that there is no SMTP server installed on localhost or anything
like that. The user should not need to specifiy an SMTP server.
Don't worry about DNS. For your purposes, you shouldn't need to worry about
it.
I do need to worry about DNS, because when sending email, I cannot
simply lookup the A address of the domain, I must look up the MX
address.

Yours,

Gratemyl
 
G

Gunnar Hjalmarsson

Gratemyl said:
I do not have access to any local or other SMTP server for my sender.
Without installation of specification of an SMTP server, my script
should be able to send mail - by directly contacting the SMTP server
for the receipient's domain.

What makes you assume that the recipient's SMTP server is configured to
relay a message from your program?
 
T

Tintin

Gratemyl said:
I meant that there is no SMTP server installed on localhost or anything
like that. The user should not need to specifiy an SMTP server.
I do need to worry about DNS, because when sending email, I cannot
simply lookup the A address of the domain, I must look up the MX
address.

To summarise, are you saying you want to send an email via SMTP directly to
the mail server of the recipient as dictated by the MX record for the
recipients domain?

If you're not allow to use modules, perhaps you would consider calling
nslookup in your Perl script.
 
J

Joe Smith

The only piece of code which I would need is to talk directly to the
DNS server.

In that case, the solution is trivial and obvious.
Copy-and-paste the contents of Net::DNS into your source code.
-Joe
 
G

Gratemyl

The receipient's SMTP does not need to RELAY mail for me, only RECEIVE
the mail - and deliver it to a local mailbox

Yours,

Gratemyl
 
G

Gratemyl

If I call nslookup, I am dependant upon an external script...but thanks
anyway.

Yours,

Gratemyl
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top