Rails
config.action_mailer.delivery_method = :smtpconfig.action_mailer.perform_deliveries = trueconfig.action_mailer.raise_delivery_errors = trueconfig.action_mailer.default_url_options = { host: "acme.com", protocol: "https" }
config.action_mailer.smtp_settings = { address: "smtp.spacepost.dev", port: 25976, user_name: "spacepost", password: ENV.fetch("SPACEPOST_API_KEY"), authentication: :plain, enable_starttls_auto: true}enable_starttls_auto: true stellt die Verbindung vor der Anmeldung per STARTTLS auf Verschlüsselung um. Setze weder ssl: true noch tls: true: Implizites TLS (Port 465) wird noch nicht angeboten.
class ApplicationMailer < ActionMailer::Base default from: "Acme <hello@acme.com>" layout "mailer"endFüge Tags oder einen Zeitplan pro E-Mail hinzu:
class UserMailer < ApplicationMailer def welcome(user) headers["X-SpacePost-Tags"] = "category=welcome" mail(to: user.email, subject: "Welcome to Acme") endendNutze Active Job (deliver_later), damit ein langsamer SMTP-Aufruf nie eine Web-Anfrage blockiert.
bin/rails runner 'ActionMailer::Base.mail(from: "hello@acme.com", to: "delivered@test.spacepost.dev", subject: "Test", body: "It works").deliver_now'