2013-05-09 78 views
6

我試圖編寫一個bash腳本,由一個cron任務運行,它會在特定情況下向我發送一封電子郵件。從命令行使用sendmail

爲了嘗試並獲得sendmail的我Sendgrid SMTP設置工作,我已經編輯了/etc/postfix/main.cf中文件有以下幾點:

smtp_sasl_password_maps = static:<username>:<password> 
smtp_sasl_security_options = noanonymous 
smtp_tls_security_level = may 
smtp_tls_security_level=encrypt 
header_size_limit = 4096000 
relayhost = [smtp.sendgrid.net]:587 

我使用重新啓動後綴須藤/etc/init.d/postfix重啓

,並使用以下命令在命令行中嘗試發送電子郵件:

sendmail的[email protected] < /tmp/email.txt

這將導致以下的輸出:

您在/ var /郵件有新郵件/ Ubuntu的

爲什麼是不是sendgrid使用我在main.cf中指定的Sendgrid SMTP詳細信息與我的電子郵件發送?

請注意,這個問題只涉及sendmail,我不想安裝其他SMTP客戶端和應用程序,它需要按原樣工作。

回答

10

我的Postfix配置有誤。我需要使用以下命令:

smtp_sasl_auth_enable = yes 
smtp_sasl_password_maps = static:<username>:<password> 
smtp_sasl_security_options = noanonymous 
smtp_tls_security_level = may 
header_size_limit = 4096000 
relayhost = [smtp.sendgrid.net]:587 

通過bash腳本發送電子郵件完成如下:

sendmail [email protected] <<EOF 
subject:This is a test 
from:[email protected] 
Body message here... 
EOF