Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Working with Emails (POP3, IMAP, SMTP e.t.c) in Erlang? [closed]

How can one handle email related communications pragmatically in Erlang/OTP? Using bash, python or Perl scripts, its possible for one to send out emails. However, in Erlang, i have not yet found an Application or built in function dedicated to sending and/or receiving emails on behalf of other applications.
In yaws, there is a mail application located in the applications path of the web server.However, on the yaws home page, there is no documentation dedicated to this application. In Nitrogen Web framework, i have found nothing yet useful as far as email protocols are concerned.
If any one knows of a library which i can use for sending and/or receiving mails pragmatically, could please direct me. Also there could be unofficial implementations as well that i do not know of. thanks, in advance

like image 246
Muzaaya Joshua Avatar asked Nov 21 '25 07:11

Muzaaya Joshua


2 Answers

I've been successfully using smtp_fsm.erl for sending emails (not exactly this version, but this one is publicly accessible).

Quick search showed some other smtp- and email-related packages, but I don't have experience with any of these.

  • https://github.com/Vagabond/gen_smtp
  • https://github.com/archaelus/esmtp
  • https://github.com/tonyg/erlang-smtp
like image 50
alavrik Avatar answered Nov 24 '25 01:11

alavrik


If you want to send emails with Erlang, you should take a look at the transactional email service AlphaMail.

Here is an example of how to send an email with the AlphaMail module for Erlang:

Service = alphamail:email_service("YOUR-ACCOUNT-API-TOKEN-HERE").
Payload = alphamail:message_payload(
    2,                                                                          % Project id
    alphamail:email_contact(<<"Sender Name">>, <<"[email protected]">>),         % Sender
    alphamail:email_contact(<<"Joe E. Receiver">>, <<"[email protected]">>, 1234), % Receiver (with receiver id)
    % Any JSON serializable payload data
    [
        {"userId", 1234},
        {"name", {struct, [
            {"first", "Joe"},
            {"last", "E. Receiver"},
        ]}},
        {"dateOfBirth", 1989}
    ]
).
alphamail:queue(Service, Payload).

And as your HTML/Comlang template:

<html>
    <body>
        <b>Name:</b> <# payload.name.first " " payload.name.last #><br>
        <b>Date of Birth:</b> <# payload.dateOfBirth #><br>

        <# if (payload.userId != null) { #>
            <a href="/sign-up">Sign Up Free!</a>
        <# } else { #>
            <a href="/login?id=<# payload.userId #>">Sign In</a>
        <# } #>
    </body>
</html>

Disclosure: I'm one of the developers behind AlphaMail

like image 28
Timothy E. Johansson Avatar answered Nov 24 '25 01:11

Timothy E. Johansson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!