How to use Email::Mime with sendmail












2















I am trying to send HTML email using a script. I will have to use native unix things and Email::Mime since those are the only thing I found installed in the box i am stuck with. I am creating a Email::Mime message and sending it to sendmail.



But i keep getting Error: No recipient addresses found in header
I have seen other RUBY scripts using sendmail so that works for this box.



Can someone help me with what I might be doing wrong in the below snippet?



sub send_mail(){

use MIME::QuotedPrint;
use HTML::Entities;
use IO::All;
use Email::MIME;

# multipart message
my @parts = (
Email::MIME->create(
attributes => {
content_type => "text/html",
disposition => "attachment",
encoding => "quoted-printable",
charset => "US-ASCII",
},
body_str => "Hello there!",
),
);

my $email = Email::MIME->create(
header_str => [
To => 'abc@xxx.com',
From => 'abc@xxx.com',
Subject => "Test Email",
],
parts => [@parts],
);

# die $email->as_string;
# die YAML::XS::Dump(%mail);

open(MAIL, "|/usr/sbin/sendmail -t");

print MAIL $email;

close (MAIL);

}


Thanks in advance.










share|improve this question


















  • 1





    You could just use Email::Sender::Simple. It's designed to work with Email::MIME and it defaults to using sendmail.

    – Grinnz
    Nov 24 '18 at 3:20
















2















I am trying to send HTML email using a script. I will have to use native unix things and Email::Mime since those are the only thing I found installed in the box i am stuck with. I am creating a Email::Mime message and sending it to sendmail.



But i keep getting Error: No recipient addresses found in header
I have seen other RUBY scripts using sendmail so that works for this box.



Can someone help me with what I might be doing wrong in the below snippet?



sub send_mail(){

use MIME::QuotedPrint;
use HTML::Entities;
use IO::All;
use Email::MIME;

# multipart message
my @parts = (
Email::MIME->create(
attributes => {
content_type => "text/html",
disposition => "attachment",
encoding => "quoted-printable",
charset => "US-ASCII",
},
body_str => "Hello there!",
),
);

my $email = Email::MIME->create(
header_str => [
To => 'abc@xxx.com',
From => 'abc@xxx.com',
Subject => "Test Email",
],
parts => [@parts],
);

# die $email->as_string;
# die YAML::XS::Dump(%mail);

open(MAIL, "|/usr/sbin/sendmail -t");

print MAIL $email;

close (MAIL);

}


Thanks in advance.










share|improve this question


















  • 1





    You could just use Email::Sender::Simple. It's designed to work with Email::MIME and it defaults to using sendmail.

    – Grinnz
    Nov 24 '18 at 3:20














2












2








2








I am trying to send HTML email using a script. I will have to use native unix things and Email::Mime since those are the only thing I found installed in the box i am stuck with. I am creating a Email::Mime message and sending it to sendmail.



But i keep getting Error: No recipient addresses found in header
I have seen other RUBY scripts using sendmail so that works for this box.



Can someone help me with what I might be doing wrong in the below snippet?



sub send_mail(){

use MIME::QuotedPrint;
use HTML::Entities;
use IO::All;
use Email::MIME;

# multipart message
my @parts = (
Email::MIME->create(
attributes => {
content_type => "text/html",
disposition => "attachment",
encoding => "quoted-printable",
charset => "US-ASCII",
},
body_str => "Hello there!",
),
);

my $email = Email::MIME->create(
header_str => [
To => 'abc@xxx.com',
From => 'abc@xxx.com',
Subject => "Test Email",
],
parts => [@parts],
);

# die $email->as_string;
# die YAML::XS::Dump(%mail);

open(MAIL, "|/usr/sbin/sendmail -t");

print MAIL $email;

close (MAIL);

}


Thanks in advance.










share|improve this question














I am trying to send HTML email using a script. I will have to use native unix things and Email::Mime since those are the only thing I found installed in the box i am stuck with. I am creating a Email::Mime message and sending it to sendmail.



But i keep getting Error: No recipient addresses found in header
I have seen other RUBY scripts using sendmail so that works for this box.



Can someone help me with what I might be doing wrong in the below snippet?



sub send_mail(){

use MIME::QuotedPrint;
use HTML::Entities;
use IO::All;
use Email::MIME;

# multipart message
my @parts = (
Email::MIME->create(
attributes => {
content_type => "text/html",
disposition => "attachment",
encoding => "quoted-printable",
charset => "US-ASCII",
},
body_str => "Hello there!",
),
);

my $email = Email::MIME->create(
header_str => [
To => 'abc@xxx.com',
From => 'abc@xxx.com',
Subject => "Test Email",
],
parts => [@parts],
);

# die $email->as_string;
# die YAML::XS::Dump(%mail);

open(MAIL, "|/usr/sbin/sendmail -t");

print MAIL $email;

close (MAIL);

}


Thanks in advance.







perl mime-types sendmail






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 23 '18 at 21:48









justrajdeepjustrajdeep

378416




378416








  • 1





    You could just use Email::Sender::Simple. It's designed to work with Email::MIME and it defaults to using sendmail.

    – Grinnz
    Nov 24 '18 at 3:20














  • 1





    You could just use Email::Sender::Simple. It's designed to work with Email::MIME and it defaults to using sendmail.

    – Grinnz
    Nov 24 '18 at 3:20








1




1





You could just use Email::Sender::Simple. It's designed to work with Email::MIME and it defaults to using sendmail.

– Grinnz
Nov 24 '18 at 3:20





You could just use Email::Sender::Simple. It's designed to work with Email::MIME and it defaults to using sendmail.

– Grinnz
Nov 24 '18 at 3:20












2 Answers
2






active

oldest

votes


















2














print MAIL $email;


should be



print MAIL $email->as_string;





share|improve this answer































    0














    First of all, if your E-Mail server requires authentication (which most do of course), you need to specify a SMTP session:



    $transport = EMail::Sender::Transport::SMTP::Persistent->new({
    # host, port, ssl, etc
    })


    Furthermore, I think you don't actually need to create the content as an own MIME-content.
    I did use something similar to this in my own work:



    $email = Email::MIME->Create(
    header_str => [ ... ],
    body_str => $message,
    attributes => {
    charset => 'UTF-8',
    encoding => 'base64',
    content_type => 'text/html',
    }
    )


    After sending your mail via sendmail($email, { transport => $transport }), you need to close the session through $transport->disconnect.



    For your application you might to adapt several things like the actual sending protocol (if different from SMTP) or the attributes hash contents.






    share|improve this answer
























    • Re "you need to specify a SMTP session", The question asked how to use sendmail, not SMTP.

      – ikegami
      Nov 24 '18 at 7:33











    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53453265%2fhow-to-use-emailmime-with-sendmail%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    print MAIL $email;


    should be



    print MAIL $email->as_string;





    share|improve this answer




























      2














      print MAIL $email;


      should be



      print MAIL $email->as_string;





      share|improve this answer


























        2












        2








        2







        print MAIL $email;


        should be



        print MAIL $email->as_string;





        share|improve this answer













        print MAIL $email;


        should be



        print MAIL $email->as_string;






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 23 '18 at 22:15









        ysthysth

        78k494191




        78k494191

























            0














            First of all, if your E-Mail server requires authentication (which most do of course), you need to specify a SMTP session:



            $transport = EMail::Sender::Transport::SMTP::Persistent->new({
            # host, port, ssl, etc
            })


            Furthermore, I think you don't actually need to create the content as an own MIME-content.
            I did use something similar to this in my own work:



            $email = Email::MIME->Create(
            header_str => [ ... ],
            body_str => $message,
            attributes => {
            charset => 'UTF-8',
            encoding => 'base64',
            content_type => 'text/html',
            }
            )


            After sending your mail via sendmail($email, { transport => $transport }), you need to close the session through $transport->disconnect.



            For your application you might to adapt several things like the actual sending protocol (if different from SMTP) or the attributes hash contents.






            share|improve this answer
























            • Re "you need to specify a SMTP session", The question asked how to use sendmail, not SMTP.

              – ikegami
              Nov 24 '18 at 7:33
















            0














            First of all, if your E-Mail server requires authentication (which most do of course), you need to specify a SMTP session:



            $transport = EMail::Sender::Transport::SMTP::Persistent->new({
            # host, port, ssl, etc
            })


            Furthermore, I think you don't actually need to create the content as an own MIME-content.
            I did use something similar to this in my own work:



            $email = Email::MIME->Create(
            header_str => [ ... ],
            body_str => $message,
            attributes => {
            charset => 'UTF-8',
            encoding => 'base64',
            content_type => 'text/html',
            }
            )


            After sending your mail via sendmail($email, { transport => $transport }), you need to close the session through $transport->disconnect.



            For your application you might to adapt several things like the actual sending protocol (if different from SMTP) or the attributes hash contents.






            share|improve this answer
























            • Re "you need to specify a SMTP session", The question asked how to use sendmail, not SMTP.

              – ikegami
              Nov 24 '18 at 7:33














            0












            0








            0







            First of all, if your E-Mail server requires authentication (which most do of course), you need to specify a SMTP session:



            $transport = EMail::Sender::Transport::SMTP::Persistent->new({
            # host, port, ssl, etc
            })


            Furthermore, I think you don't actually need to create the content as an own MIME-content.
            I did use something similar to this in my own work:



            $email = Email::MIME->Create(
            header_str => [ ... ],
            body_str => $message,
            attributes => {
            charset => 'UTF-8',
            encoding => 'base64',
            content_type => 'text/html',
            }
            )


            After sending your mail via sendmail($email, { transport => $transport }), you need to close the session through $transport->disconnect.



            For your application you might to adapt several things like the actual sending protocol (if different from SMTP) or the attributes hash contents.






            share|improve this answer













            First of all, if your E-Mail server requires authentication (which most do of course), you need to specify a SMTP session:



            $transport = EMail::Sender::Transport::SMTP::Persistent->new({
            # host, port, ssl, etc
            })


            Furthermore, I think you don't actually need to create the content as an own MIME-content.
            I did use something similar to this in my own work:



            $email = Email::MIME->Create(
            header_str => [ ... ],
            body_str => $message,
            attributes => {
            charset => 'UTF-8',
            encoding => 'base64',
            content_type => 'text/html',
            }
            )


            After sending your mail via sendmail($email, { transport => $transport }), you need to close the session through $transport->disconnect.



            For your application you might to adapt several things like the actual sending protocol (if different from SMTP) or the attributes hash contents.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 23 '18 at 21:55









            Thomas LangThomas Lang

            39317




            39317













            • Re "you need to specify a SMTP session", The question asked how to use sendmail, not SMTP.

              – ikegami
              Nov 24 '18 at 7:33



















            • Re "you need to specify a SMTP session", The question asked how to use sendmail, not SMTP.

              – ikegami
              Nov 24 '18 at 7:33

















            Re "you need to specify a SMTP session", The question asked how to use sendmail, not SMTP.

            – ikegami
            Nov 24 '18 at 7:33





            Re "you need to specify a SMTP session", The question asked how to use sendmail, not SMTP.

            – ikegami
            Nov 24 '18 at 7:33


















            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53453265%2fhow-to-use-emailmime-with-sendmail%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Sphinx de Gizeh

            Dijon

            Langue