2012-06-15 33 views
1

如何在我的Zend_Mail_Transport_Smtp中使用Amazon SES密鑰,祕密+ smtp地址? 它說:Must issue a STARTTLS command first而試圖跟隨。如何在我的Zend_Mail_Transport_Smtp適配器中使用Amazon SES密鑰,secret + smtp地址?

/* 
    Reference in C#: http://sesblog.amazon.com/ 

    String username = "SMTP-USERNAME"; // Replace with your SMTP username. 
    String password = "SMTP-PASSWORD"; // Replace with your SMTP password. 
    String host = "email-smtp.us-east-1.amazonaws.com"; 
    int port = 25; 

    */ 
    public static function sendEmail($to, $subject, $body) { 
    $config = array(
     'aws_key' => 'yourkey', 
     'aws_secret' => 'yourkeysecret', 
    )); 

    // 
    //echo 0 > /selinux/enforce 
    //$tr = new Zend_Mail_Transport_Smtp('smtp.belgacom.be');// works - for local 
    //$tr = new Zend_Mail_Transport_Smtp('out.telenet.be'); // works - for office 
    // 
    $tr = new Zend_Mail_Transport_Smtp(
         'email-smtp.us-east-1.amazonaws.com'); // DOES not work 
    Zend_Mail::setDefaultTransport($tr); 

    $mail = new Zend_Mail(); 
    $html = self::setupEmail($body); 
    $mail->setBodyHtml($html); 
    $mail->setFrom('[email protected]', 'memy.com'); 
    $mail->addTo($to, 'EXAMPLE'); 
    $mail->setSubject($subject); 
    $mail->send(); 
    } 

追問:

// Wild guess 
$config = array(
    'aws_key' => 'yourkey', 
    'aws_secret' => 'yourkeysecret', 
)); 
$tr = new Zend_Mail_Transport_Smtp('email-smtp.us-east-1.amazonaws.com', 
            $config); 

末次隨訪:

步驟1)要使用亞馬遜SES SMTP接口發送電子郵件,你將需要:

  • AWS賬戶。

  • 亞馬遜SES生產訪問,如果你想發送大量的電子郵件。有關更多信息,請參閱請求生產訪問。

    - 這件事以後,他們允許send 10000 emails per 24 hour period

    - 這被迅速激活喜歡小於24小時

    - 5封電子郵件/秒

  • 的電子郵件地址,您已完成與亞馬遜SES。有關更多信息,請參閱驗證電子郵件地址。

    - 這需要同時通過他們

    驗證 - 這仍然是24小時後尚未證實

  • 的SMTP接口的主機名和端口號。主機名是email-smtp.us-east-1.amazonaws.com。端口號因連接方式而異。有關更多信息,請參閱連接到SMTP端點。

    - 否則非常重要,它是做不到這一點,你從AWS管理控制檯獲得

  • 的SMTP用戶名和密碼。有關更多信息,請參閱SMTP憑據。

  • 可使用TLS(傳輸層安全性)進行通信的客戶端軟件。

步驟2)我上面那些完成,在那裏管理控制檯它表明:

Status: 
pending verification (resend) 
Please check your inbox for an email to this address, and click on the link provided to complete verification. If you did not receive this email, please click resend. 

Domain verification in AWS: 

Status: 
pending verification (resend) 
Please check your inbox for an email to this address, and click on the link provided to complete verification. If you did not receive this email, please click resend. 

,這意味着,他們將72小時

步驟3)內做一些事情在不使用外部適配器的情況下修改$ config(未由ZF移位)

$config = array(
    'auth' => 'login', 
    'username' => 'SES key', 
    'password' => 'SES secret', 
)); 
$tr = new Zend_Mail_Transport_Smtp('email-smtp.us-east-1.amazonaws.com', 
            $config); 

回答

5

我想最簡單的方法就是使用這個加載項:Amazon-SES-Zend-Mail-Transport。另一方面,如果您通過Zend_Mail_Transport挖掘自己,則可以自己編寫它。

編輯

Response: 530 Must issue a STARTTLS command first意味着你需要讓你驗證之前的安全連接。

另請確保在通過SMTP連接時使用的是SES SMTP credentials。這些憑證與您的AWS憑證不同。從您發佈的代碼看來,您可能正在使用AWS憑據。

並檢查提供在GitHub上的自述)

EDIT 2

嘗試增加給你的配置:

$config = array('ssl' => 'tls','port' => 25); 

編輯3

554 Message rejected: Email address is not verified甚至出現地址已經過驗證。一些想法爲什麼它不工作:

1.)驗證的地址是區分大小寫的,所以如果你使用它與你驗證的不同的情況下,你會遇到問題。這歸結於rfc的嚴格解釋。 - >檢查該

2)我認爲亞馬遜不喜歡基於角色的地址一樣[email protected] - >檢查該

+0

「它不工作」 是一個比較含糊;)什麼是發生確切的錯誤? – dom

+1

@YumYumYum檢查我的編輯... – dom

+0

1)我已經完成了所有這些提到的這些http://docs.amazonwebservices.com/ses/latest/DeveloperGuide/SMTP.html?r=9608 2)我現在正在使用開始SES SMTP證書(不是AWS證書3)仍然給出了這個530 4)這是否意味着,有技術人員必須手動修改我的帳戶的東西,然後它會被激活? – YumYumYum

1

另一個跟進。

爲了幫助他人解決同樣的問題,下面是我最近用來正確工作的確切步驟。

使用此首先https://github.com/christophervalles/Amazon-SES-Zend-Mail-Transport

然後將此:

$mail = new Zend_Mail('utf-8'); 
$transport = new App_Mail_Transport_AmazonSES(
    array(
     'accessKey' => 'YOUR_ACCESS_KEY', 
     'privateKey' => 'YOUR_PRIVATE_KEY' 
    ) 
); 
$mail->addTo('[email protected]', 'Recipient') 
    ->setFrom('[email protected]', 'Webmaster') 
    ->setSubject('Email subject line') 
    ->setBodyText('Email body') 
    ->send($transport); 

有關詳細信息和可能的錯誤: http://shakyshane.com/blog/amazon_ses_zend_framework.html

+0

請注意,由於兩個原因,不鼓勵裸鏈接到您自己的網站/產品;首先,答案應作爲獨立答案發布,而不是僅僅連接到外部網站。其次,自我推銷往往會在這裏被忽視,並且經常被標記爲垃圾郵件(特別是如果沒有披露您將鏈接到您自己的網站/產品)。 –

+0

同樣的事情你如何在ZF2做? – YumYumYum

相關問題