Örnekler gönderiliyor

Python ile gönder

Python'dan e-posta gönderme, talepler kütüphanesi ile.

Önkoşullar

  • SENDTERN_API_KEY olarak depolanan bir Sendtern API anahtarı
  • Python 3.8 or newer
  1. 1

    Kurulum talepleri

    Herhangi bir HTTP istemcisi çalışabilir. Bu rehber requests kullanır.

    1pip install requests
    
  2. 2

    E-posta gönder

    Create send.py.

    1# send.py
    2import os
    3import uuid
    4import requests
    5
    6res = requests.post(
    7    "https://sendtern.com/emails",
    8    headers={
    9        "Authorization": f"Bearer {os.environ['SENDTERN_API_KEY']}",
    10        "Idempotency-Key": str(uuid.uuid4()),
    11    },
    12    json={
    13        "from": "Acme <hello@mail.example.com>",
    14        "to": ["you@example.com"],
    15        "subject": "Hello from Python",
    16        "html": "<p>It works!</p>",
    17    },
    18    timeout=10,
    19)
    20
    21res.raise_for_status()
    22print(res.json())
    
  3. 3

    Cevapları kontrol et.

    Başarılı bir talep e-posta kimliğiyle 200 OK'yi geri verir. Daha sonra e-postayı aramaya kullanın.

    1{
    2  "id": "47be30ca-24b7-48fb-b35d-ff287b89e66d"
    3}
    

Örnek göndericiyi verilen alan adı adresinizle değiştirin.