我没有依赖我的主机发送电子邮件,而是考虑使用我的Gmail帐户发送电子邮件.这些电子邮件是我在节目中播放的乐队的个性化电子邮件.有可能吗?
我在Ubuntu 12.04 TLS VPS上使用Ruby MRI 2.0.0和Rails 3.2.12,并尝试在我的应用程序中设置电子邮件通知.几天前工作正常,但现在不行了.我的网站主机是OVH.
我的SMTP设置:
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
ActionMailer::Base.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:user_name => 'sender@gmail.com',
:password => 'secret',
:authentication => 'plain',
:enable_starttls_auto => true
}
Run Code Online (Sandbox Code Playgroud)
使用RAILS_ENV=production rails console:
class MyMailer < ActionMailer::Base
def test_email
sender = "sender@gmail.com"
receiver = "receiver@example.com"
mail from: sender, to: receiver, subject: "Hello!", body: "World!!"
end
end
=> nil
MyMailer.test_email.deliver
Run Code Online (Sandbox Code Playgroud)
输出:
Net::OpenTimeout: execution expired
from ~/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/net/smtp.rb:540:in `initialize'
from ~/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/net/smtp.rb:540:in `open'
from …Run Code Online (Sandbox Code Playgroud) 我用PHP编写了一个类,用于发送使用Gmail帐户的邮件.该类又使用PHPMailer库.该设置是Windows Vista上的WAMP 2.4.使用microtime()PHP中的函数,我发现发送一封邮件需要5到6秒.在这种设置上运行的PHP脚本是否正常,我需要花费5-6秒才能发送一封邮件.这是该类的代码.
<?php
require_once("phpmailer/class.phpmailer.php");
require_once("phpmailer/class.smtp.php");
class Mailer {
// Needs to be set per object
public $subject;
public $message;
public $to_name;
public $to;
private $mail; // This is the main mail object that'll be initialized
public function __construct() {
// Need to create a PHPMailer object in the constuctor and return it for use in this class.
$mail = new PHPMailer();
$from_name = "bleh";
$from = "bleh@gmail.com";
$username = "bleh";
$password = "bleh";
$mail->FromName = $from_name;
$mail->From …Run Code Online (Sandbox Code Playgroud) smtp ×3
email ×2
gmail ×2
.net ×1
actionmailer ×1
c# ×1
performance ×1
php ×1
phpmailer ×1
smtp-auth ×1
smtpclient ×1