Send the mail directly to that user : Email POP3 « Network « Ruby

Send the mail directly to that user

require 'resolv'
require 'net/smtp'

from = ""
to = ""

message = <<MESSAGE_END
From: #{from}
To: #{to}
Subject: Direct e-mail test
This is a test e-mail message.

to_domain = to.match(/\@(.+)/)[1] do |dns|
  mail_servers = dns.getresources(to_domain, Resolv::DNS::Resource::IN::MX)
  mail_server = mail_servers[rand(mail_servers.size)].exchange.to_s

  Net::SMTP.start(mail_server) do |smtp|
    smtp.send_message message, from, to


Related examples in the same category

1.connect to a POP3 server to see if there are any messages available for download
2.Downloading all the mails is as simple as using the pop method for each Net::POPMail object:
3.To delete a mail
4.deletes messages if their subject contains the word "medicines":
5.Sending Mail with SMTP
6.e-mail provider
7.specify port number