Sendcorex

การส่งถึงกล่องจดหมาย

การเข้ากล่องจดหมาย+62%

98.4%

Gmail
Outlook
Yahoo

อีเมลของคุณเข้ากล่องจดหมาย ไม่ใช่ถังสแปม

ตรวจติดตามการส่งถึงฟรีในทุกแพ็กเกจ

ดูเพิ่มเติม
บทเรียน

ส่งอีเมลด้วย Ruby on Rails ผ่าน SMTP

Action Mailer ตั้งค่าครั้งเดียวใน initializer แล้วส่งได้จากทุกที่ในแอป

โดยทีม Sendcorex·อัปเดต 21 ก.ย. 2026·อ่าน 7 นาที

ตั้งค่า Action Mailer

ใน config/environments/production.rb (หรือ initializer):

config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
  address: 'smtp.sendcorex.com',
  port: 587,
  user_name: ENV['SENDCOREX_API_KEY'],
  password: ENV['SENDCOREX_API_KEY'],
  authentication: 'plain',
  enable_starttls_auto: true,
}
config.action_mailer.default_url_options = { host: 'yourdomain.com' }

สร้างและส่ง mailer

rails generate mailer Welcome
class WelcomeMailer < ApplicationMailer
  default from: 'Your App <hello@yourdomain.com>'

  def welcome_email(user)
    @user = user
    mail(to: @user.email, subject: 'Welcome!')
  end
end

# from anywhere in your app
WelcomeMailer.welcome_email(user).deliver_later

ใช้ deliver_later กับ queue adapter (Sidekiq, Solid Queue) แทน deliver_now เพื่อไม่ให้การเชื่อมต่อ SMTP ที่ช้าบล็อกคำขอเว็บ

ข้อผิดพลาดที่พบบ่อย

อาการวิธีแก้
Net::SMTPAuthenticationErrorตรวจว่าตัวแปรสภาพแวดล้อมถูกโหลดและใช้ทั้ง user_name และ password
อีเมลไม่ออกจากคิวตรวจว่า queue adapter (เช่น Sidekiq) ทำงานจริงในสภาพแวดล้อมนั้น

ส่งอีเมลแรกในไม่กี่นาที

สร้างบัญชีฟรี ยืนยันโดเมน แล้ววางโค้ดด้านบน

ไม่ต้องใช้บัตรเครดิต