Any example of sending mail with template (boss_mail:send_template(my_application, foo_message, [Arg1, Arg2, ...])) ??

43 views
Skip to first unread message

Mert Öztürk

unread,
Jan 6, 2016, 4:16:47 PM1/6/16
to ChicagoBoss
Hello,

I succeed integrating mandrill smtp api and mailing plain text with "smtp.mandrillapp.com" but could not find any source or example using templates through ChicagoBoss.
Read Chicagoboss documentation but couldn't understand ----> boss_mail:send_template(my_application, foo_message, [Arg1, Arg2, ...])
foo_message is the function in myapp_outgoing_mail_controller.erl with the variables Arg1,Arg2.. but still couldnt understand how to get content from view folder and where to put sender and recipent??
Is there any example of using .html templates in my mail with dynamic variables?

Many thanks
Mert

Ángel Herranz

unread,
Jan 18, 2016, 2:15:02 AM1/18/16
to ChicagoBoss
You just need the template foo_message.html in directory src/mail/view. Did you try it?

Mert Öztürk

unread,
Jan 26, 2016, 6:14:04 PM1/26/16
to ChicagoBoss
Hello Angel,

Yes i made it. Just struggling to pass values from controller to html form with django template but still could not succeeded.
Could not find any implementation done before.

Thanks
Mert


18 Ocak 2016 Pazartesi 09:15:02 UTC+2 tarihinde Ángel Herranz yazdı:

chan sisowath

unread,
Jan 26, 2016, 11:17:48 PM1/26/16
to chica...@googlegroups.com
hi,

 i have this from an app i have done before.
 not sure how it behave now with latest CB.

ail
├── view
│   ├── notification.html
│   └── notification.txt
├── myapp_mail_incoming_mail_controller.erl
└── myapp_mail_outgoing_mail_controller.erl

-module(myapp_mail_outgoing_mail_controller).
-export ([notification/1]).

notification(Email) ->   
    {
     ok,
     Email:from(),
     Email:to(),
     Email:headers(),
     Email:attributes(),
     [{charset, "utf-8"}]
    }.

%%% ----- mail model
-module(mail, [Id,
               FromName,
               From,
               To,
               ToName,
               Subject,
               Message,
               Html,
               DateCreated,
               Charset,
               Lang
               ]).

-define (MAIL_FROM, "no-r...@mydomain.com").
-define (MAIL_NAME, "MYDOMAIN Mail System").

-export([humanize_from/0]).
-export([b64_subject/0]).
-export([headers/0]).

humanize_from() ->
    case THIS:from_name() of
        undefined -> THIS:from();
        Name      -> string:join ([Name, " <", THIS:from(), ">"], "")
    end.

b64_subject() ->
    SubjB64 = base64:encode_to_string (THIS:subject()),
    string:join(["=?UTF-8?B?", SubjB64, "?="], "").

headers() ->
  [
   {              "To", THIS:to()},
   {            "From", THIS:humanize_from()},
   {         "Subject", THIS:b64_subject()},
   %{"Content-Language", THIS:lang()},
   {    "Content-Type", "text/plain; charset=UTF-8"}
  ].

here the basic call to send the mail:

do_sendmail(EmailAttrs) ->
     M = boss_record:new(mail, EmailAttrs),
     {ok, EMail} = M:save(),    
     boss_mail:send_template(vikvon_mail, notification, [EMail]).

mihawk.





--
You received this message because you are subscribed to the Google Groups "ChicagoBoss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chicagoboss...@googlegroups.com.
Visit this group at https://groups.google.com/group/chicagoboss.
To view this discussion on the web visit https://groups.google.com/d/msgid/chicagoboss/e9c1dd4c-f39e-47e3-8e67-24466445cb69%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

chan sisowath

unread,
Jan 27, 2016, 4:23:52 AM1/27/16
to chica...@googlegroups.com
do_sendmail(EmailAttrs) ->
     M = boss_record:new(mail, EmailAttrs),
     {ok, EMail} = M:save(),    
     boss_mail:send_template(myapp, notification, [EMail]).

Mert Öztürk

unread,
Jan 27, 2016, 4:24:49 AM1/27/16
to ChicagoBoss
Hello Chan,

Thanks for prompt reply.
I solved it like below;

verification_email(FromAddress, ToAddress, Subject, Name, VerificationCode) ->
    Headers = [
        {"Subject", Subject},
        {"To", ToAddress},
        {"From", FromAddress},
        {"Name", Name}
    ],
    Attributes = [
        {"Name",Name},
        {"Code", VerificationCode}
    ],
    {ok, FromAddress, ToAddress, Headers,Attributes}.

And Django line like this;

Hello {{ Name }}. Thank you for joining...

Thanks
Mert

6 Ocak 2016 Çarşamba 23:16:47 UTC+2 tarihinde Mert Öztürk yazdı:
Reply all
Reply to author
Forward
0 new messages