ProductPromotion
Logo

Elixir

made by https://0x3d.site

GitHub - kbrw/mailibex: Library containing Email related implementations in Elixir : dkim, spf, dmark, mimemail, smtp
Library containing Email related implementations in Elixir : dkim, spf, dmark, mimemail, smtp - kbrw/mailibex
Visit Site

GitHub - kbrw/mailibex: Library containing Email related implementations in Elixir : dkim, spf, dmark, mimemail, smtp

GitHub - kbrw/mailibex: Library containing Email related implementations in Elixir : dkim, spf, dmark, mimemail, smtp

mailibex Build Status

Library containing Email related implementations in Elixir : dkim, spf, dmark, mimemail, smtp

MimeMail

%MimeMail{headers: [{key::atom, {:raw,binary} | MimeMail.Header.t}], body: binary | [MimeMail.t] | {:raw,binary}}
# headers contains a keywordlist of either the raw form of the header, 
# or an encodable version of the header (a term with a module implementing MimeMail.Header.to_ascii)
# body contains either the raw binary body, the decoded body as a binary (using content-transfer-encoding), 
# or a list of MimeMail struct to encode in case of a multipart
# If body is a text, then the decoded body binary will be the UTF8 version of the text converted from the source charset
  • MimeMail.from_string parse the mimemail binary into a MimeMail struct explained above, with all the headers and body in their encoded form ({:raw,binary})
  • MimeMail.encode_headers(mail) apply the MimeMail.Header.to_ascii to every header to convert them into a {:raw,binary} form.
  • MimeMail.decode_headers(mail,[Mod1,Mod2]) applies successively Mod1.decode_headers(mail) the Mod2.decode_headers(mail) to the result.
  • MimeMail.encode_body(mail) encodes the mail body from a decoded form (binary | [MimeMail]) into a {:raw,binary}form
  • MimeMail.decode_body(mail) does the opposite.
  • MimeMail.to_string(mail) encode headers and body of a MimeMail into an ascii mail binary.

Currently, the library contains three types of acceptable header value (implementing MimeMail.Header) :

  • binary : simple binary headers are utf8 strings converted into encoded words
  • {value,%{}=params} are only acceptable tuple as header, converted into a 'content-*' style header ( value; param1=value1, param2=value2)
  • [%MimeMail.Address{name="toto", address: "[email protected]"}] : lists are encoded into mailbox list header
  • %DKIM{} : Converted into a dkim header

So for instance :

%MimeMail{headers: [
    to: [%MimeMail.Address{name: "You",address: "[email protected]"}],
    from: [%MimeMail.Address{name: "Me",address: "[email protected]"}],
    cc: "[email protected]", # only ascii so ok to encode it as a simple encoded word
    'content-type': {'text/plain',%{charset: "utf8"}},
  ],
  body: "Hello world"}
|> MimeMail.to_string

FlatMail

Flat mail representation of MimeMail is simply a KeywordList where all the keys [:txt,:html,:attach,:attach_in,:include] are used to construct the body tree of alternative/mixed/related multiparts in the body field of the MimeMail struct, and the rest of the KeywordList became the header field.

MimeMail.Flat.to_mail(from: "[email protected]", txt: "Hello world", attach: "attached plain text", attach: File.read!("attachedfile"))
|> MimeMail.to_string

Need more explanations here...

MimeTypes

ext2mime and mime2ext are functions generated at compilation time from the apache mime configuration file https://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types .

"image/png" = MimeTypes.ext2mime(".png")
".png" = MimeTypes.mime2ext("image/png")

bin2ext matches the begining of the binary and sometimes decode the binary in order to determine the file extension (then we can use ext2mimeto find the mime type if needed.

".webm" = MimeTypes.bin2ext(File.read!("path/to/my/webm/file.webm"))

DKIM

[rsaentry] =  :public_key.pem_decode(File.read!("test/mails/key.pem"))
mail = MimeMail.from_string(data)

mail = DKIM.sign(mail,:public_key.pem_entry_decode(rsaentry), d: "order.brendy.fr", s: "cobrason")
case DKIM.check(mail) do
  :none      ->IO.puts("no dkim signature")
  {:pass,{key,org}}      ->IO.puts("the mail is signed by #{key} at #{org}")
  :tempfail  -> IO.puts("the dns record is unavailable, try later")
  {:permfail,msg}->IO.puts("the sender is not authorized because #{msg}")
end

Need more explanations here...

DMARC

Organizational Domain implementation using public suffix database : (https://publicsuffix.org/list/effective_tld_names.dat)

"orga2.gouv.fr" = DMARK.organization "orga0.orga1.orga2.gouv.fr"

SPF

Full implementation of the Sender Policy Framework (https://tools.ietf.org/html/rfc7208).

case SPF.check("[email protected]",{1,2,3,4}, helo: "relay.com", server_domain: "me.com") do
  :none      ->IO.puts("no SPF information")
  :neutral   ->IO.puts("nor authorized neither not authorized")
  :pass      ->IO.puts("the sender is authorized")
  {:fail,msg}->IO.puts("the sender is not authorized because #{msg}")
  :softfail  ->IO.puts("not authorized but don't be rude")
  :temperror ->IO.puts("temporary error, try again latter")
  :permerror ->IO.puts("spf error, ask to remote admin")
end

Current Status

  • DKIM is fully implemented (signature/check), missing DKIM-Quoted-Printable token management
  • mimemail encoding/decoding of headers and body are fully implemented
  • flat mime body representation for easy mail creation / modification
  • DMARC implementation of organizational domains
  • SPF is fully implemented

TODO :

  • DMARC report
  • smtp client implementation
  • smtp server implementation over Ranch

CONTRIBUTING

Hi, and thank you for wanting to contribute. Please refer to the centralized informations available at: https://github.com/kbrw#contributing

Articles
to learn more about the elixir concepts.

Resources
which are currently available to browse on.

mail [email protected] to add your project or resources here 🔥.

FAQ's
to know more about the topic.

mail [email protected] to add your project or resources here 🔥.

Queries
or most google FAQ's about Elixir.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory