{
    "mode": "perldoc",
    "parameter": "Mail::Sendmail",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/Mail%3A%3ASendmail/json",
    "generated": "2026-06-14T00:53:08Z",
    "synopsis": "use Mail::Sendmail;\n%mail = ( To      => 'you@there.com',\nFrom    => 'me@here.com',\nMessage => \"This is a very short message\"\n);\nsendmail(%mail) or die $Mail::Sendmail::error;\nprint \"OK. Log says:\\n\", $Mail::Sendmail::log;",
    "sections": {
        "NAME": {
            "content": "Mail::Sendmail - Simple platform independent mailer\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "use Mail::Sendmail;\n\n%mail = ( To      => 'you@there.com',\nFrom    => 'me@here.com',\nMessage => \"This is a very short message\"\n);\n\nsendmail(%mail) or die $Mail::Sendmail::error;\n\nprint \"OK. Log says:\\n\", $Mail::Sendmail::log;\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "Simple platform independent e-mail from your perl script. Only requires Perl 5 and a network\nconnection.\n\nMail::Sendmail takes a hash with the message to send and sends it to your mail server. It is\nintended to be very easy to setup and use. See also \"FEATURES\" below, and as usual, read this\ndocumentation.\n\nThere is also a FAQ (see \"NOTES\").\n",
            "subsections": []
        },
        "INSTALLATION": {
            "content": "Best\n\"perl -MCPAN -e \"install Mail::Sendmail\"\"\n\nTraditional\nperl Makefile.PL\nmake\nmake test\nmake install\n\nManual\nCopy Sendmail.pm to Mail/ in your Perl lib directory.\n\n(eg. c:\\Perl\\site\\lib\\Mail\\\nor  /usr/lib/perl5/siteperl/Mail/\nor whatever it is on your system.\nThey are listed when you type C< perl -V >)\n\nActivePerl's PPM\nDepending on your PPM version:\n\nppm install --location=http://alma.ch/perl/ppm Mail-Sendmail\n\nor\n\nppm install http://alma.ch/perl/ppm/Mail-Sendmail.ppd\n\nBut this way you don't get a chance to have a look at other files (Changes, Todo, test.pl,\n...).\n\nAt the top of Sendmail.pm, set your default SMTP server(s), unless you specify it with each\nmessage, or want to use the default (localhost).\n\nInstall MIME::QuotedPrint. This is not required but strongly recommended.\n",
            "subsections": []
        },
        "FEATURES": {
            "content": "Automatic time zone detection, Date: header, MIME quoted-printable encoding (if\nMIME::QuotedPrint installed), all of which can be overridden.\n\nBcc: and Cc: support.\n\nAllows real names in From:, To: and Cc: fields\n\nDoesn't send an X-Mailer: header (unless you do), and allows you to send any header(s) you want.\n\nConfigurable retries and use of alternate servers if your mail server is down\n\nGood plain text error reporting\n\nExperimental support for SMTP AUTHentication\n",
            "subsections": []
        },
        "LIMITATIONS": {
            "content": "Headers are not encoded, even if they have accented characters.\n\nSince the whole message is in memory, it's not suitable for sending very big attached files.\n\nThe SMTP server has to be set manually in Sendmail.pm or in your script, unless you have a mail\nserver on localhost.\n\nDoesn't work on OpenVMS, I was told. Cannot test this myself.\n",
            "subsections": []
        },
        "CONFIGURATION": {
            "content": "Default SMTP server(s)\nThis is probably all you want to configure. It is usually done through *$mailcfg{smtp}*,\nwhich you can edit at the top of the Sendmail.pm file. This is a reference to a list of SMTP\nservers. You can also set it from your script:\n\n\"unshift @{$Mail::Sendmail::mailcfg{'smtp'}} , 'my.mail.server';\"\n\nAlternatively, you can specify the server in the *%mail* hash you send from your script,\nwhich will do the same thing:\n\n\"$mail{smtp} = 'my.mail.server';\"\n\nA future version will (hopefully) try to set useful defaults for you during the Makefile.PL.\n\nOther configuration settings\nSee *%mailcfg* under \"DETAILS\" below for other configuration options.\n",
            "subsections": []
        },
        "DETAILS": {
            "content": "sendmail()\nsendmail is the only thing exported to your namespace by default\n\n\"sendmail(%mail) || print \"Error sending mail: $Mail::Sendmail::error\\n\";\"\n\nIt takes a hash containing the full message, with keys for all headers and the body, as well as\nfor some specific options.\n\nIt returns 1 on success or 0 on error, and rewrites $Mail::Sendmail::error and\n$Mail::Sendmail::log.\n\nKeys are NOT case-sensitive.\n\nThe colon after headers is not necessary.\n\nThe Body part key can be called 'Body', 'Message' or 'Text'.\n\nThe SMTP server key can be called 'Smtp' or 'Server'. If the connection to this one fails, the\nother ones in $mailcfg{smtp} will still be tried.\n\nThe following headers are added unless you specify them yourself:\n\nMime-Version: 1.0\nContent-Type: 'text/plain; charset=\"iso-8859-1\"'\n\nContent-Transfer-Encoding: quoted-printable\nor (if MIME::QuotedPrint not installed)\nContent-Transfer-Encoding: 8bit\n\nDate: [string returned by timetodate()]\n\nIf you wish to use an envelope sender address different than the From: address, set\n$mail{Sender} in your %mail hash.\n\nThe following are not exported by default, but you can still access them with their full name,\nor request their export on the use line like in: \"use Mail::Sendmail qw(sendmail $addressrx\ntimetodate);\"\n\nembedding options in your %mail hash\nThe following options can be set in your %mail hash. The corresponding keys will be removed\nbefore sending the mail.\n\n$mail{smtp} or $mail{server}\nThe SMTP server to try first. It will be added\n\n$mail{port}\nThis option will be removed. To use a non-standard port, set it in your server name:\n\n$mail{server}='my.smtp.server:2525' will try to connect to port 2525 on server\nmy.smtp.server\n\n$mail{auth}\nThis must be a reference to a hash containing all your authentication options:\n\n$mail{auth} = \\%options; or $mail{auth} = {user=>\"username\", password=>\"password\",\nmethod=>\"DIGEST-MD5\", required=>0 };\n\nuser\nusername\n\npass or password\npassword\n\nmethod\noptional method. compared (stripped down) to available methods. If empty, will try all\navailable.\n\nrequired\noptional. defaults to false. If set to true, no delivery will be attempted if\nauthentication fails. If false or undefined, and authentication fails or is not\navailable, sending is tried without.\n\n(different auth for different servers?)\n\nMail::Sendmail::timetodate()\nconvert time ( as from \"time()\" ) to an RFC 822 compliant string for the Date header. See also\n\"%Mail::Sendmail::mailcfg\".\n\n$Mail::Sendmail::error\nWhen you don't run with the -w flag, the module sends no errors to STDERR, but puts anything it\nhas to complain about in here. You should probably always check if it says something.\n\n$Mail::Sendmail::log\nA summary that you could write to a log file after each send\n\n$Mail::Sendmail::addressrx\nA handy regex to recognize e-mail addresses.\n\nA correct regex for valid e-mail addresses was written by one of the judges in the obfuscated\nPerl contest... :-) It is quite big. This one is an attempt to a reasonable compromise, and\nshould accept all real-world internet style addresses. The domain part is required and comments\nor characters that would need to be quoted are not supported.\n\nExample:\n$rx = $Mail::Sendmail::addressrx;\nif (/$rx/) {\n$address=$1;\n$user=$2;\n$domain=$3;\n}\n\n%Mail::Sendmail::mailcfg\nThis hash contains installation-wide configuration options. You normally edit it once (if ever)\nin Sendmail.pm and forget about it, but you could also access it from your scripts. For\nreadability, I'll assume you have imported it (with something like \"use Mail::Sendmail",
            "subsections": [
                {
                    "name": "qw",
                    "content": "The keys are not case-sensitive: they are all converted to lowercase before use. Writing\n\"$mailcfg{Port} = 2525;\" is OK: the default $mailcfg{port} (25) will be deleted and replaced\nwith your new value of 2525.\n\n$mailcfg{smtp}\n\"$mailcfg{smtp} = [qw(localhost my.other.mail.server)];\"\n\nThis is a reference to a list of smtp servers, so if your main server is down, the module\ntries the next one. If one of your servers uses a special port, add it to the server name\nwith a colon in front, to override the default port (like in my.special.server:2525).\n\nDefault: localhost.\n\n$mailcfg{from}\n\"$mailcfg{from} = 'Mailing script me@mydomain.com';\"\n\nFrom address used if you don't supply one in your script. Should not be of type\n'user@localhost' since that may not be valid on the recipient's host.\n\nDefault: undefined.\n\n$mailcfg{mime}\n\"$mailcfg{mime} = 1;\"\n\nSet this to 0 if you don't want any automatic MIME encoding. You normally don't need this,\nthe module should 'Do the right thing' anyway.\n\nDefault: 1;\n\n$mailcfg{retries}\n\"$mailcfg{retries} = 1;\"\n\nHow many times should the connection to the same SMTP server be retried in case of a\nfailure.\n\nDefault: 1;\n\n$mailcfg{delay}\n\"$mailcfg{delay} = 1;\"\n\nNumber of seconds to wait between retries. This delay also happens before trying the next\nserver in the list, if the retries for the current server have been exhausted. For CGI\nscripts, you want few retries and short delays to return with a results page before the http\nconnection times out. For unattended scripts, you may want to use many retries and long\ndelays to have a good chance of your mail being sent even with temporary failures on your\nnetwork.\n\nDefault: 1 (second);\n\n$mailcfg{tz}\n\"$mailcfg{tz} = '+0800';\"\n\nNormally, your time zone is set automatically, from the difference between \"time()\" and\n\"gmtime()\". This allows you to override automatic detection in cases where your system is\nconfused (such as some Win32 systems in zones which do not use daylight savings time: see\nMicrosoft KB article Q148681)\n\nDefault: undefined (automatic detection at run-time).\n\n$mailcfg{port}\n\"$mailcfg{port} = 25;\"\n\nPort used when none is specified in the server name.\n\nDefault: 25.\n\n$mailcfg{debug}\n\"$mailcfg{debug} = 0;\"\n\nPrints stuff to STDERR. Current maximum is 6, which prints the whole SMTP session, except\ndata exceeding 500 bytes.\n\nDefault: 0;\n\n$Mail::Sendmail::VERSION\nThe package version number (you can not import this one)\n"
                },
                {
                    "name": "Configuration variables from previous versions",
                    "content": "The following global variables were used in version 0.74 for configuration. As from version\n0.781, they are not supported anymore. Use the *%mailcfg* hash if you need to access the\nconfiguration from your scripts.\n\n$Mail::Sendmail::defaultsmtpserver\n$Mail::Sendmail::defaultsmtpport\n$Mail::Sendmail::defaultsender\n$Mail::Sendmail::TZ\n$Mail::Sendmail::connectretries\n$Mail::Sendmail::retrydelay\n$Mail::Sendmail::useMIME\n"
                }
            ]
        },
        "ANOTHER EXAMPLE": {
            "content": "use Mail::Sendmail;\n\nprint \"Testing Mail::Sendmail version $Mail::Sendmail::VERSION\\n\";\nprint \"Default server: $Mail::Sendmail::mailcfg{smtp}->[0]\\n\";\nprint \"Default sender: $Mail::Sendmail::mailcfg{from}\\n\";\n\n%mail = (\n#To      => 'No to field this time, only Bcc and Cc',\n#From    => 'not needed, use default',\nBcc     => 'Someone <him@there.com>, Someone else her@there.com',\n# only addresses are extracted from Bcc, real names disregarded\nCc      => 'Yet someone else <xz@whatever.com>',\n# Cc will appear in the header. (Bcc will not)\nSubject => 'Test message',\n'X-Mailer' => \"Mail::Sendmail version $Mail::Sendmail::VERSION\",\n);\n\n\n$mail{Smtp} = 'specialserver.for-this-message-only.domain.com';\n$mail{'X-custom'} = 'My custom additional header';\n$mail{'mESSaGE : '} = \"The message key looks terrible, but works.\";\n# cheat on the date:\n$mail{Date} = Mail::Sendmail::timetodate( time() - 86400 );\n\nif (sendmail %mail) { print \"Mail sent OK.\\n\" }\nelse { print \"Error sending mail: $Mail::Sendmail::error \\n\" }\n\nprint \"\\n\\$Mail::Sendmail::log says:\\n\", $Mail::Sendmail::log;\n\nAlso see http://alma.ch/perl/Mail-Sendmail-FAQ.html for examples of HTML mail and sending\nattachments.\n",
            "subsections": []
        },
        "CHANGES": {
            "content": "Main changes since version 0.79:\n\nExperimental SMTP AUTH support (LOGIN PLAIN CRAM-MD5 DIGEST-MD5)\n\nFix bug where one refused RCPT TO: would abort everything\n\nsend EHLO, and parse response\n\nBetter handling of multi-line responses, and better error-messages\n\nNon-conforming line-endings also normalized in headers\n\nNow keeps the Sender header if it was used. Previous versions only used it for the MAIL FROM:\ncommand and deleted it.\n\nSee the Changes file for the full history. If you don't have it because you installed through\nPPM, you can also find the latest one on http://alma.ch/perl/scripts/Sendmail/Changes.\n",
            "subsections": []
        },
        "NOTES": {
            "content": "MIME::QuotedPrint is used by default on every message if available. It allows reliable sending\nof accented characters, and also takes care of too long lines (which can happen in HTML mails).\nIt is available in the MIME-Base64 package at http://www.perl.com/CPAN/modules/by-module/MIME/\nor through PPM.\n\nLook at http://alma.ch/perl/Mail-Sendmail-FAQ.html for additional info (CGI, examples of sending\nattachments, HTML mail etc...)\n\nYou can use this module freely. (Someone complained this is too vague. So, more precisely: do\nwhatever you want with it, but be warned that terrible things will happen to you if you use it\nbadly, like for sending spam, or ...?)\n\nThanks to the many users who sent me feedback, bug reports, suggestions, etc. And please excuse\nme if I forgot to answer your mail. I am not always reliable in answering mail. I intend to set\nup a mailing list soon.\n\nLast revision: 06.02.2003. Latest version should be available on CPAN:\nhttp://www.cpan.org/modules/by-authors/id/M/MI/MIVKOVIC/.\n\nOn Debian systems Sys::Hostname::Long is tried before Sys::Hostname in order get a fully\nqualified domain name.\n",
            "subsections": []
        },
        "AUTHOR": {
            "content": "Milivoj Ivkovic <mi\\x40alma.ch> (\"\\x40\" is \"@\" of course)\n",
            "subsections": []
        },
        "COPYRIGHT": {
            "content": "Copyright (c) 1998-2017 Milivoj Ivkovic. All rights reserved. This program is free software; you\ncan redistribute it and/or modify it under the same terms as Perl itself.\n",
            "subsections": []
        }
    },
    "summary": "Mail::Sendmail - Simple platform independent mailer",
    "flags": [],
    "examples": [],
    "see_also": []
}