NAME

Para::Frame::Email::Sending - For sending emails

DESCRIPTION

Put the email templates under $home/email/.

SYNOPSIS

Using the default send_mail paraframe action:

    [% META next_action='send_mail' %]
    <p> Name [% input('name') %]
    <p> Email [% input('email') %]
    <p> Message [% textarea('body') %]
    <p> [% submit('Send the mail') %]

Set the Para::Frame::Site/email variable in the site configuration.

See Para::Frame::Email::Sending::send_mail

new

  Para::Frame::Email::Sending->new( \%params )

Creates the Email sender object.

The default params for the email are:

  u    = The active L<Para::Frame::User> object (for the application)
  q    = The active L<CGI> object
  date = The L<Para::Frame::Time/date> function
  site = The L<Para::Frame::Site> object

The given params can replace and add to this list. They are given to /set.

Returns the object.

set

  $e->set( \%params )

Adds and/or replaces the params to use for sending this email.

Params with special meaning are:

  body
  body_html
#  body_encoded
  by_proxy
  envelope_from
  envelope_from_addr
  from
  from_addr
#  header
#  header_rendered_to
  in_reply_to
  message_id
#  mime_lite
  pgpsign
  references
  reply_to
  sender
  subject
  template
  to

params

  $s->params

Returns the hashref of params.

good

  $listref = $s->good()
  @list    = $s->good()
  $bool    = $s->good($email)

In scalar context, it retuns a hashref of addresses successfully sent to.

In list context, it returns a list of addresses sucessfully sent to.

If given an $email returns true if this address was sucessfully sent to.

bad

  $listref = $s->bad()
  @list    = $s->bad()
  $bool    = $s->bad($email)

In scalar context, it retuns a hashref of addresses not sent to.

In list context, it returns a list of addresses not sent to.

If given an $email returns true if this address was not sent to.

error_msg

  $s->error_msg

Returns the error messages generated or the empty string.

send_in_fork

  $fork = Para::Frame::Email::Sending->send_in_fork( \%params )
  $fork = Para::Frame::Email::Sending->send_in_fork()
  $fork = $s->send_in_fork( \%params )
  $fork = $s->send_in_fork()

Sends the email in a fork. Throws an exception if failure occured.

Returns the fork.

The return message in the fork is taken from $params{return_message} or the default "Email delivered".

Calls /send with the given params.

Example:

  $fork = Para::Frame::Email::Sending->send_in_fork( \%params )
  $fork->yield;
  return "" if $fork->failed;

send_in_background

  Para::Frame::Email::Sending->send_in_background( \%params )
  Para::Frame::Email::Sending->send_in_background()
  $s->send_in_background( \%params )
  $s->send_in_background()

Sends the email in the background. That is. Send it between other requests. This will make the site unaccessable while the daemin waits for the recieving email server to answer.

Throws an exception if failure occured.

Returns true if sucessful.

Calls /send with the given params.

send_by_proxy

  Para::Frame::Email::Sending->send_by_proxy( \%params )
  Para::Frame::Email::Sending->send_by_proxy()
  $s->send_by_proxy( \%params )
  $s->send_by_proxy()

Sends the email using a proxy like sendmail.

Adds the param by_proxy = 1

Throws an exception if failure occured.

The return message is taken from $params{return_message} or the default "Email delivered".

Calls /send with the given params.

send

  Para::Frame::Email::Sending->send( \%params )
  Para::Frame::Email::Sending->send()
  $s->send( \%params )
  $s->send()

Calls /set with the given params, adding or replacing the existing params.

Results stays with the sender object. Create a new sender object for resetting the result.

The required params are:

  template  = Which TT template to use for the email
  from      = The sender email address
  subject   = The subject line of the email
  to        = The reciever email address

Optional params:

  pgpsign   = Signs the email with pgpsign
  reply_to  = Adds a Reply-To header to the email
  by_proxy  = Sens email using sendmail

The template are searched for in the $home/email/ dir under the site home. If the template starts with /, it will not be prefixed by $home/email/.

to can be a ref to a list of email addresses to try. We try them in the given order. Quits after the furst sucessful address.

Sends all the params to the TT template for rendering.

With param pgpsign, signs the resulting email by calling /pgpsign with the email content and the param value.

Makes the form address an object using Para::Frame::Email::Address/parse.

Makes the to addresses objects by using Para::Frame::Email::Address/parse.

Encodes the to, form and subject fields of the email by using mime encoding.

Sends the email in the format quoted-printable.

If sending by_proxy, we will not get any indication if the email was sucessfully sent or not.

Returns true on success or false on failure to send email.

Exceptions:

notfound - Hittar inte e-postmallen ...

mail - Failed to parse address $p->{'from'}

Example:

  my $emailer = Para::Frame::Email::Sending->new({
    template => 'registration_confirmation.tt',
    from     => '"The registry office" <registry@mydomain.com>',
    to       => $recipient_email,
    subject  => "Welcome to our site",
  });
  $emailer->send or throw('email', $emailer->err_msg);

pgpsign

  pgpsign( $dataref, $configfile )

This is called by $s-gtsend() if the param pgpsign has $configfile as value.

The signing is done by Crypt::OpenPGP using Compat PGP5 and ConfigFile $configfile.

Modifies $dataref.

Return true on success.

Exceptions:

action - The error given by Crypt::OpenPGP/sign

generate_message_id

Generates a unique message id, without surrounding <>.

Given in the form $cnt.$epoch.$port.pf\@$fqdn

The pf is for giving som kind of namespace that hopefully will differ it from other mail services on this domain.

Supported args are:

  time

Returns: The message id, without surrounding <>

renderer

email

SEE ALSO

Para::Frame, Para::Frame::Email::Address