Mail::Sendmail – Simple platform independent mailer – metacpan.org

  • name
  • synopsis
  • description
  • installation
  • characteristics
  • limitations
  • settings
  • details
    • sendmail()
      • embed options in your %mailhash

      mail::sendmail – simple independent sending platform

      simple, platform-independent email from your perl script. it only requires perl 5 and a network connection.

      mail::sendmail takes a hash of the message to send and sends it to your mail server. it is meant to be very easy to set up and use. see also “features” below and, as usual, read this documentation.

      there are also frequently asked questions (see “notes”).

      perl -mcpan -e “install mail::sendmail”

      copy sendmail.pm to mail/ in your perl lib directory.

      depending on your version of ppm:

      or

      but this way you don’t have a chance to take a look at other files (changes, to-dos, test.pl, …).

      at the top of sendmail.pm, set your default smtp server(s), unless you specify it with every message, or want to use the default (localhost).

      install mime::quotedprint. this is not required, but is strongly recommended.

      timezone autodetection, date:header, mime quoted printable encoding (if mime::quotedprint is installed), all of which can be overridden.

      cc: and cc: support.

      allow real names in the from:, to: and cc: fields

      does not send an x-mailer: header (unless you do) and allows you to send any header you want.

      configurable retries and use of alternate servers if your mail server is down

      good plain text error reporting

      experimental support for smtp authentication

      headers are not encoded, even if they have accented characters.

      Since the entire message is in memory, it is not suitable for sending very large attachments.

      The smtp server must be configured manually in sendmail.pm or in your script, unless you have a mail server on localhost.

      doesn’t work in openvms, I was told. I can’t test this myself.

      this is probably all you want to configure. This is usually done via $mailcfg{smtp}, which you can edit at the top of the sendmail.pm file. this is a reference to a list of smtp servers. you can also set it from your script:

      unshift @{$mail::sendmail::mailcfg{‘smtp’}} , ‘my.mail.server’;

      Alternatively, you can specify the server in the %mail hash you send from your script, which will do the same thing:

      $mail{smtp} = ‘my.mail.server’;

      a future version will (hopefully) try to set useful defaults for you during the makefile.pl.

      see %mailcfg in “details” below for other configuration options.

      sendmail()

      sendmail is the only thing that is exported to your namespace by default

      sendmail(%mail) || print “error sending mail: $mail::sendmail::errorn”;

      A hash is needed that contains the entire message, with keys for all headers and body, as well as some specific options.

      returns 1 on success or 0 on error, and rewrites $mail::sendmail::error and $mail::sendmail::log.

      keys are not case sensitive.

      colons after headers are not required.

      the key of the body part can be called ‘body’, ‘message’ or ‘text’.

      the smtp server key can be called ‘smtp’ or ‘server’. if the connection to this fails, the others in $mailcfg{smtp} will still be tried.

      The following headers are added unless you specify them yourself:

      if you want to use an envelope sender address other than the from: address, set $mail{sender} in your %mail hash.

      the following are not exported by default, but you can still access them with their full name or request their export in the use line as in: use mail::sendmail qw(sendmail $address_rx time_to_date);

      embed options in your %mailhash

      The following options can be set in your %mail hash. the corresponding keys will be removed before sending the mail.

      the smtp server to test first. will be added

      this option will be removed. to use a non-standard port, set it to your server name:

      $mail{server}=’my.smtp.server:2525′ will try to connect to port 2525 on server my.smtp.server

      this should be a reference to a hash containing all your authentication options:

      $mail{authorization} = %options; or $mail{auth} = {user=>”username”, password=>”password”, method=>”digest-md5″, required=>0 };

      username

      password

      Optional method. compared (summarized) with available methods. if empty, it will try all available ones.

      optional. default is false. if set to true, delivery will not be attempted if authentication fails. if false or undefined, and authentication fails or is unavailable, send without is attempted.

      (different authentication for different servers?)

      mail::sendmail::time_to_date()

      converts the time (from time()) to an rfc 822 compliant string for the date header. see also “%mail::sendmail::mailcfg”.

      $mail::sendmail::error

      When not run with the -w flag, the module does not send errors to stderr, but puts anything it has to complain about here. you should probably always check if it says something.

      $mail::sendmail::log

      a digest that could be written to a log file after each submission

      $mail::sendmail::rx_address

      a regular expression useful for recognizing email addresses.

      one of the judges in the obfuscated perl contest wrote a correct regular expression for valid email addresses… 🙂 it’s pretty big. this is an attempt at a reasonable compromise and you must accept all real world internet style addresses. the domain part is required and comments or characters that need to be quoted are not allowed.

      %mail::sendmail::mailcfg

      This hash contains configuration options for the entire installation. you usually edit it once (if ever) in sendmail.pm and forget about it, but you can also access it from your scripts. for readability, I’ll assume you’ve imported it (with something like use mail::sendmail qw(sendmail %mailcfg)).

      keys are not case sensitive: they are all converted to lowercase before use. writing $mailcfg{port} = 2525; ok: the default $mailcfg{port} (25) will be removed and replaced with your new value of 2525.

      $mailcfg{smtp} = [qw(localhost my.other.mail.server)];

      This is a reference to a list of smtp servers, so if your main server is down, the module tries the next one. if one of your servers uses a special port, add it to the server name with a colon in front of it, to override the default port (as in my.special.server:2525).

      default: localhost.

      $mailcfg{from} = ‘mail script me@mydomain.com’;

      from the address used if you don’t provide one in your script. should not be of type ‘user@localhost’ as it may not be valid on the recipient’s host.

      default: undefined.

      $mailcfg{mime} = 1;

      set this to 0 if you don’t want any automatic mime encoding. normally you don’t need this, the module should ‘do the right thing’ anyway.

      default: 1;

      $mailcfg{retries} = 1;

      how many times should the connection to the same smtp server be retried in case of failure?

      default: 1;

      $mailcfg{delay} = 1;

      number of seconds to wait between retries. this delay also occurs before trying the next server in the list, if retries for the current server have been exhausted. for cgi scripts, you need few retries and short delays to return with a page of results before the http connection times out. for unattended scripts, you may want to use lots of retries and long delays to have a good chance of getting your mail through even with temporary failures on your network.

      default: 1 (second);

      $mailcfg{tz} = ‘+0800’;

      Usually your time zone is set automatically, from the difference between time() and gmtime(). this allows you to override automatic detection in cases where your system is confused (such as some win32 systems in areas that do not use daylight saving time – see microsoft kb article q148681)

      default: undefined (automatic detection at runtime).

      $mailcfg{port} = 25;

      port used when none is specified in the server name.

      default: 25.

      $mailcfg{debug} = 0;

      print stuff to stderr. the current maximum is 6, which prints the entire smtp session, except for data that exceeds 500 bytes.

      default: 0;

      $mail::sendmail::version

      the version number of the package (you cannot import this)

      previous version configuration variables

      The following global variables were used in version 0.74 for configuration. as of version 0.78_1, they are no longer supported. use the %mailcfg hash if you need to access the configuration from your scripts.

      main changes since version 0.79:

      experimental smtp authentication support (simple login cram-md5 digest-md5)

      fix bug where one refused to rcpt: would abort all

      send ehlo and parse the response

      better handling of multiline responses and better error messages

      non-conforming line endings have also been normalized in headers

      now keeps the sender header if it was used. previous versions only used it for the mail from: command and removed it.

      see the changelog for the full history. if you don’t have it because you installed it via ppm, you can also find the latest at http://alma.ch/perl/scripts/sendmail/changes.

      mime::quotedprint is used by default in every message if it is available. it allows reliable sending of accented characters and also takes care of lines that are too long (which can happen in html mails). it is available in the mime-base64 package at http://www.perl.com/cpan/modules/by-module/mime/ or via ppm.

      You can use this module freely. (someone complained that this is too vague. so more precisely: do whatever you want with it, but be aware that terrible things will happen to you if you misuse it, like spamming or…?)

      thanks to the many users who sent me feedback, bug reports, suggestions, etc. and sorry if i forgot to answer your mail. I am not always reliable to answer the mail. I intend to set up a mailing list soon.

      last revision: 06.02.2003. the latest version should be available on cpan: http://www.cpan.org/modules/by-authors/id/m/mi/mivkovic/.

      milivoj ivkovic <mix40alma.ch> (“x40” is “@”, of course)

      copyright (c) 1998-2017 milivoj ivkovic. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as perl itself.

      See Also:  Transfer Juno Email to Gmail - How to Bulk Import Juno Email into Gmail

Leave a Reply

Your email address will not be published. Required fields are marked *