Getting Started
Send transactional email via SMTP or the HTTP API. Both require a client certificate (mTLS) for authentication.
Go
SMTP
import (
"crypto/tls"
"net/smtp"
)
func sendMail() error {
cert, _ := tls.LoadX509KeyPair("client.crt", "client.key")
conn, _ := tls.Dial("tcp", "smtp.ataca.io:465", &tls.Config{
Certificates: []tls.Certificate{cert},
})
c, _ := smtp.NewClient(conn, "smtp.ataca.io")
c.Mail("noreply@ataca.io")
c.Rcpt("user@example.com")
w, _ := c.Data()
w.Write([]byte("Subject: Hello\r\n\r\nHi!"))
w.Close()
return c.Quit()
}
HTTP API
cert, _ := tls.LoadX509KeyPair("client.crt", "client.key")
client := &http.Client{Transport: &http.Transport{
TLSClientConfig: &tls.Config{Certificates: []tls.Certificate{cert}},
}}
body := `{"from":"noreply@ataca.io",` +
`"to":["user@example.com"],` +
`"subject":"Hello","body_text":"Hi!"}`
resp, _ := client.Post(
"https://smtp.ataca.io/v1/send",
"application/json",
strings.NewReader(body),
)
Python
SMTP
import smtplib, ssl
ctx = ssl.create_default_context()
ctx.load_cert_chain("client.crt", "client.key")
with smtplib.SMTP_SSL("smtp.ataca.io", 465, context=ctx) as s:
s.sendmail(
"noreply@ataca.io",
["user@example.com"],
"Subject: Hello\r\n\r\nHi!",
)
HTTP API
import requests
resp = requests.post(
"https://smtp.ataca.io/v1/send",
cert=("client.crt", "client.key"),
json={
"from": "noreply@ataca.io",
"to": ["user@example.com"],
"subject": "Hello",
"body_text": "Hi!",
},
)
Rust
SMTP
use lettre::{Transport, SmtpTransport, Message};
use lettre::transport::smtp::client::TlsParameters;
let email = Message::builder()
.from("noreply@ataca.io".parse()?)
.to("user@example.com".parse()?)
.subject("Hello")
.body("Hi!".to_string())?;
// Load client cert for mTLS
let tls = TlsParameters::builder("smtp.ataca.io".into())
.add_root_certificate(ca_cert)
.identity(client_identity)
.build()?;
let mailer = SmtpTransport::relay("smtp.ataca.io")?
.port(465)
.tls(lettre::transport::smtp::client::Tls::Wrapper(tls))
.build();
mailer.send(&email)?;
HTTP API
let client = reqwest::Client::builder()
.identity(identity) // mTLS client cert
.build()?;
let resp = client.post("https://smtp.ataca.io/v1/send")
.json(&serde_json::json!({
"from": "noreply@ataca.io",
"to": ["user@example.com"],
"subject": "Hello",
"body_text": "Hi!",
}))
.send().await?;