這是Byron Jones (https://www.glob.com.au/sendmail/) 的假sendmail程式的復興,如果您不需要TLS v1.1或v1.2支持,請使用原始版本,這兩個版本都沒有可用的支持,並且都沒有積極維護。
sendmail.exe 是一個簡單的 Windows 控制台應用程序,它模擬 sendmail 的 -t 選項來透過標準輸入傳送電子郵件。
它的目的是簡化執行將 /usr/lib/sendmail 硬編碼為電子郵件傳遞方式或使用 sendmail 管道方法的程式的 UNIX 程式碼,例如 Windows 上的 php 使用。
它不支援延遲傳遞,並且需要 smtp 伺服器來執行訊息的實際傳遞。
我已經使用假sendmail程式很多年了,但是當使用Office 365 smtp伺服器時,TLS v1.0已經不夠了,他們需要TLS v1.2,所以我嘗試重新編譯Byron Jones的源代碼包含在他的網站上的發布中。經過一些小修改和一些小的更改,我能夠在 Embarcadero 的 Delphi builder 10.3 (Rio) 當前社區版本中重新編譯 Delphi 2007 程式。其中包含較新的 Indy 版本,支援 TLS v1.2 並在 sendmail 程式碼中強制使用 TLS v1.1+。
為了避免其他人從原始碼重新編譯偽造的 sendmail 的麻煩,我在這個 github 網站上提供了它,包括原始碼,就像原始版本一樣。
從這個 github 下載 sendmail.zip 並將其內容解壓縮到系統上的臨時資料夾中
將 sendmail.exe、sendmail.ini 和兩個 .dll 檔案複製到安裝 UNIX 應用程式的磁碟機上的 usrlib 中。例如。如果您的應用程式安裝在c: 上,則需要將sendmail.exe 和sendmail.ini 複製到c:usrlibsendmail.exe 和c:usrlibsendmail.ini 或其他目錄(如果路徑不是)沒有在使用它的應用程式中進行硬編碼。
在sendmail.ini中設定smtp伺服器和預設網域。
一般來說,您需要做的就是在 usrlib 中安裝 sendmail.exe,並且調用 /usr/lib/sendmail 的現有程式碼就可以工作。
如果您正在編寫新的應用程序,您所需要做的就是建立具有完整標頭的電子郵件訊息,然後將其通過管道傳輸到“sendmail.exe -t”
對於 PHP,sendmail 路徑不是硬編碼的,它可以在 php.ini 檔案中配置,因此 sendmail.exe 及其檔案可以放在系統上的任何位置,配置狀態 sendmail_path 選項為“僅限 Unix”,但它適用於Windows,它會覆蓋上面的3 個僅Win32 選項,請參閱PHP 手冊(https://www.php.net/manual/en/mail.configuration.php#ini.sendmail-path)
注意:如果您的 SMTP 伺服器不需要驗證或加密,您可以只使用 SMTP 和 SMPT_PORT 設定參數來指定 smtp 伺服器,則不需要 sendmail.exe。
PHP.ini:
[mail function]
; For Win32 only.
; http://php.net/smtp
;SMTP = localhost
; http://php.net/smtp-port
;smtp_port = 25
; For Win32 only.
; http://php.net/sendmail-from
;sendmail_from = [email protected]
; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
; http://php.net/sendmail-path
sendmail_path = "C:sendmailsendmail.exe -t"
; Force the addition of the specified parameters to be passed as extra parameters
; to the sendmail binary. These parameters will always replace the value of
; the 5th parameter to mail().
;mail.force_extra_parameters =
; Add X-PHP-Originating-Script: that will include uid of the script followed by the filename
mail.add_x_header = On
在 sendmail.ini 指定 smtp 伺服器位址和使用者名稱/密碼組合
成功時,Sendmail 將 ERRORLEVEL 設定為 0。
如果電子郵件無法送達,版本 28 及更高版本會將 ERRORLEVEL 設定為 -1。該值已更改,以提供與 PHP 更好的兼容性,PHP 預計失敗時 ERRORLEVEL 為 -1。
取消註釋 sendmail.ini 中的 debug_logfile 條目並嘗試重新傳送失敗的訊息。這應該會在與 sendmail.exe 相同的目錄中建立 debug.log,顯示完整的 SMTP 記錄。
請參閱原始版本網站:https://www.glob.com.au/sendmail/
該程式在 bsd 許可證下發布:https://www.glob.com.au/sendmail/license.html
授權詳細資訊和完整原始程式碼 (Delphi 10.3 Rio) 包含在 zip 檔案和此儲存庫的來源資料夾中。