merrymonk has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to send a test e-mail with the following Perl script.
use strict; use warnings; use MIME::Entity; my $From = '<valid e-mail address>'; my $To = '<valid e-mail address>'; my $Subject = 'Test'; my $Type = 'text/plain'; my $Host = 'mail.btinternet.com'; my $msg = MIME::Entity->build( From => $From, To => $To, Subject => $Subject, Type => $Type, Data => 'This is a test message', Debug => 1 ); print "\nbefore smtpsend\n\n"; my @ok = $msg->smtpsend( Host => $Host, To => $To, Debug => 1 ); if (@ok) { print "Sent message to: ", join(', ', @ok), "\n"; } else { print "\nFailed to send message"; }
I am fairly sure that something very similar worked on my system some years ago. However, since then I have:
1. started to use Thunderbird as my e-mail application;
2. started to use Virgin Media to give broadband and internet services but I have retained by bt e-mail address.
Using this script I get the following output.

before smtpsend

Net::SMTP>>> Net::SMTP(2.31)
Net::SMTP>>> Net::Cmd(2.29)
Net::SMTP>>> Exporter(5.68) )
Net::SMTP>>> IO::Socket::INET(1.33) )
Net::SMTP>>> IO::Socket(1.37) )
Net::SMTP>>> IO::Handle(1.34) )
Net::SMTP=GLOB(0x25d4468)<<< 220 rgout03.bt.lon5.cpcloud.co.uk ESMTP Service ready)
Net::SMTP=GLOB(0x25d4468)>>> EHLO localhost.localdomain)
Net::SMTP=GLOB(0x25d4468)<<< 250-rgout03.bt.lon5.cpcloud.co.uk)
Net::SMTP=GLOB(0x25d4468)<<< 250-DSN)
Net::SMTP=GLOB(0x25d4468)<<< 250-8BITMIME)
Net::SMTP=GLOB(0x25d4468)<<< 250-PIPELINING)
Net::SMTP=GLOB(0x25d4468)<<< 250-AUTH=LOGIN)
Net::SMTP=GLOB(0x25d4468)<<< 250-AUTH LOGIN PLAIN)
Net::SMTP=GLOB(0x25d4468)<<< 250-DELIVERBY 300)
Net::SMTP=GLOB(0x25d4468)<<< 250 SIZE 41943040)
Net::SMTP=GLOB(0x25d4468)>>> MAIL FROM:<postmaster@hm-insp15>)
Net::SMTP=GLOB(0x25d4468)<<< 553 <postmaster@hm-insp15> Invalid mail address, must be fully qualified domain)
Net::SMTP=GLOB(0x25d4468)>>> QUIT)
Net::SMTP=GLOB(0x25d4468)<<< 221 rgout03.bt.lon5.cpcloud.co.uk QUIT)

Failed to send message

It seems that postmaster@hm-insp15 is not correct. What can I do to correct this?

Replies are listed 'Best First'.
Re: e-mail fails with address that is not a fully qualified domain
by stevieb (Canon) on Jun 01, 2015 at 15:40 UTC

    Where are you getting the $From address from? You need to append the rest of your domain either in the $From field, or perhaps update your machine name to be fully qualified in your /etc/hosts file.

      I just used my normal e-mail address which is <name>@btinternet.com
Re: e-mail fails with address that is not a fully qualified domain
by ww (Archbishop) on Jun 01, 2015 at 15:52 UTC
    "It seems that postmaster@hm-insp15 is not correct. What can I do to correct this?

    Step one: check with your ISP.


    ++$anecdote ne $data

    If I've misconstrued your question or the logic needed to answer it, my apologies to all those electrons which were inconvenienced by the creation of this post.
Re: e-mail fails with address that is not a fully qualified domain
by Anonymous Monk on Jun 01, 2015 at 17:42 UTC

    Ah, it would appear that you need to provide the envelope sender explicitly ( MailFrom => $From ); otherwise it falls back to some expensive guesswork (mailaddress/maildomain in Mail::Util), and that seems to be failing...

      I did try the MailFrom form as shown below (with the expanded host name). $From was my normal e-mail address
      my $msg = MIME::Entity->build( MailFrom => $From, To => $To,

      Sadly still the same error
Re: e-mail fails with address that is not a fully qualified domain
by Anonymous Monk on Jun 01, 2015 at 17:10 UTC

    You need the FQDN from short host name? Simple, just resolve it:

    my $fullname = (gethostbyname $host)[0];

      I used the gethostbyname as suggested as shown in the following Perl extract.
      my $full_host_name = (gethostbyname $Host)[0]; print "full_host_name <$full_host_name>\n"; my @ok = $msg->smtpsend( Host => $full_host_name, To => $To, Debug => 1 );
      I got the following output in which:
      1. gethostname was expanded ad I used this for the Host
      2. I still got the message about need to be fully qualified domain address
      I then tried altering the $From to include various parts of the expanded host name but without any success!
      I suspect I am close so if anyone can suggest the next step it will be much appreciated.

      full_host_name <mail.btinternet.bt.lon5.cpcloud.co.uk>

      Net::SMTP>>> Net::SMTP(2.31)
      Net::SMTP>>> Net::Cmd(2.29)
      Net::SMTP>>> Exporter(5.68)
      Net::SMTP>>> IO::Socket::INET(1.33)
      Net::SMTP>>> IO::Socket(1.37)
      Net::SMTP>>> IO::Handle(1.34)
      Net::SMTP=GLOB(0x2835118)<<< 220 rgout06.bt.lon5.cpcloud.co.uk ESMTP Service ready
      Net::SMTP=GLOB(0x2835118)>>> EHLO localhost.localdomain
      Net::SMTP=GLOB(0x2835118)<<< 250-rgout06.bt.lon5.cpcloud.co.uk
      Net::SMTP=GLOB(0x2835118)<<< 250-DSN
      Net::SMTP=GLOB(0x2835118)<<< 250-8BITMIME
      Net::SMTP=GLOB(0x2835118)<<< 250-PIPELINING
      Net::SMTP=GLOB(0x2835118)<<< 250-AUTH=LOGIN
      Net::SMTP=GLOB(0x2835118)<<< 250-AUTH LOGIN PLAIN
      Net::SMTP=GLOB(0x2835118)<<< 250-DELIVERBY 300
      Net::SMTP=GLOB(0x2835118)<<< 250 SIZE 41943040
      Net::SMTP=GLOB(0x2835118)>>> MAIL FROM:<postmaster@hm-insp15>
      Net::SMTP=GLOB(0x2835118)<<< 553 <postmaster@hm-insp15> Invalid mail address, must be fully qualified domain
      Net::SMTP=GLOB(0x2835118)>>> QUIT
      Net::SMTP=GLOB(0x2835118)<<< 221 rgout06.bt.lon5.cpcloud.co.uk QUIT