Skip to content

Evovest/SMTPClient.jl

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

82 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SMTPClient

Build Status

SMTPClient

A CURL based SMTP client with fairly low level API. It is useful for sending emails from within Julia code. Depends on LibCURL.jl.

SMTPClient requires Julia 0.7 or higher.

Installation

Pkg.add("SMTPClient")

The libCurl native library must be available. It is usually installed with the base system in most Unix variants.

Usage

using SMTPClient

opt = SendOptions(
  isSSL = true,
  username = "you@gmail.com",
  passwd = "yourgmailpassword")
#Provide the message body as RFC5322 within an IO
body = IOBuffer(
  "Date: Fri, 18 Oct 2013 21:44:29 +0100\r\n" *
  "From: You <you@gmail.com>\r\n" *
  "To: me@test.com\r\n" *
  "Subject: Julia Test\r\n" *
  "\r\n" *
  "Test Message\r\n")
url = "smtps://smtp.gmail.com:465"
rcpt = ["<me@test.com>", "<foo@test.com>"]
from = "<you@gmail.com>"
resp = send(url, rcpt, from, body, opt)
  • Sending from file IOStream is supported:

    body = open("/path/to/mail")

Gmail Notes

Due to the security policy of Gmail, you need to "allow less secure apps into your account":

Function Reference

send(url, to-addresses, from-address, message-body, options)

Send an email.

  • url should be of the form smtp://server:port or smtps://....
  • to-address is a vector of String.
  • from-address is a String. All addresses must be enclosed in angle brackets.
  • message-body must be a RFC5322 formatted message body provided via an IO.
  • options is an object of type SendOptions. It contains authentication information, as well as the option of whether the server requires TLS.
SendOptions(; isSSL = false, verbose = false, username = "", passwd = "")

Options are passed via the SendOptions constructor that takes keyword arguments. The defaults are shown above.

  • verbose: enable libcurl verbose mode or not.
  • If the username is blank, the passwd is not sent even if present.

Note that no keepalive is implemented. New connections to the SMTP server are created for each message.

About

Send emails from Julia

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Julia 65.7%
  • Python 34.3%