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는 로그인 전에 STARTTLS로 연결을 업그레이드합니다. ssl: true나 tls: true는 설정하지 마세요. 암시적 TLS(포트 465)는 아직 제공되지 않습니다.
class ApplicationMailer < ActionMailer::Base default from: "Acme <hello@acme.com>" layout "mailer"end메일마다 태그나 예약 일정을 추가합니다.
class UserMailer < ApplicationMailer def welcome(user) headers["X-SpacePost-Tags"] = "category=welcome" mail(to: user.email, subject: "Welcome to Acme") endend느린 SMTP 호출이 웹 요청을 막지 않도록 Active Job(deliver_later)을 사용하세요.
bin/rails runner 'ActionMailer::Base.mail(from: "hello@acme.com", to: "delivered@test.spacepost.dev", subject: "Test", body: "It works").deliver_now'