Search code examples
perlemailmimespam

How to send email using MIME::Lite in perl so that the mail does not end up in Spam folder


I am using MIME::Lite to send emails. I am not sending mails in bulk. I have the following code to send mail.

my $msg = MIME::Lite->new(
    To      => "$recipient_address",
    From    => "$sender_displayname <$sender_email>",
    Subject => "$subject",
    Type    => "multipart/alternative",
);
my $att_text = MIME::Lite->new(
    Type     => 'text',
    Data     => $message_body_plain,
    Encoding => 'quoted-printable',
);
$att_text->attr('content-type' => 'text/plain; charset=UTF-8');
$msg->attach($att_text);

my $att_html = MIME::Lite->new(
    Type     => 'text',
    Data     => $message_body_html,
    Encoding => 'quoted-printable',
);
$att_html->attr('content-type' => 'text/html; charset=UTF-8');
$msg->attach($att_html);

When I send mails, in few domains, like Google, the email lands in SPAM folder, whereas in Yahoo, the mail appears in INBOX. I Googled and read the documentation provided by Google and found that if the email has the seigned-by/mailed-by headers, then the email is not filtered by SPAM filter.

Following is the text which I referred:

The authentication process tries to verify the real sender by looking at a message's authentication data. This data should be included in a message's "signed-by" or "mailed-by" headers (shown beneath the subject line when you look at a message's details). When the sender doesn't include this data, we can't be sure whether or not the message was forged. For example, a message might claim to be from a Gmail address, but we can't confirm that claim if the message doesn't have authentication data.

Please help!


Solution

  • Supporting Pathak in that this is not Perl related.

    But anyway, I would try including:

    my $msg = MIME::Lite->new(
        "-Mailed-by" => 'real.mailaccount@sending-mailserver.com', 
        ...
    

    Make sure this mail address (and/or the From-mail address) actually exists, preferably on the SMTP server you are using as part of

    $msg->send('smtp', 'smtp.sending-mailserver.com')
    #(or as part of sendmail on 'nix)
    

    This often gives you far less "spam points" than if you try to send a mail with a yahoo.com mail address from e.g. a gmail.com smtp server, or using a quite public smtp server using the email address from a specific company.

    Try also to Google about how to avoid ending up in the trash, e.g. http://mailchimp.com/resources/guides/how-to-avoid-spam-filters/html/