Ubuntu配置sendmail client,用sendmail命令來發送郵件

參考文檔
https://mailoutgoing.com/support/mailrelay/sendmail.html
https://www.sendmail.org/~ca/email/auth.html
https://docs.oracle.com/en/operating-systems/oracle-linux/6/admin/configure-sendmail.html

總結
1、ubuntu環境下,sendmail服務位于/etc/init.d/sendmail而非/usr/lib/systemd/system/sendmail.service,它被service命令管理,不過類似這種被service命令管理的大部分服務也可以被systemctl管理
2、一般需要安裝sendmail和m4 sendmail-cf,因為sendmail發送郵件時不需要郵件賬號和密碼,但是需要在/etc/mail/sendmail.mc中配置郵件服務器地址,再通過m4 sendmail.mc >sendmail.cf命令把郵件服務器地址編輯到sendmail.cf
3、配置sendmail服務器的這臺需要發送郵件的機器,服務器名必須帶上.XX.com類似這樣的域名后綴,否則無法把郵件發出去并且會報錯DSN: Service unavailable
4、sendmail的語法可以是如下兩種方式

4.1(echo From: "WON Notification <notification@XXX.com>";echo To: "lukes.liao@XXXchina.com";echo To: "lukes.liao1@XXXchina.com";echo Subject: "This is test1";echo "The Content is just a test email1")| /usr/sbin/sendmail -t
4.2、sendmail -t < /root/emailtest.txt
/root/emailtest.txt內容如下
From: WON Notification <notification@XXX.com>
To: lukes.liao@XXXchina.com
To: lukes.liao1@XXXchina.com
Subject: "This is test1"
The Content is just a test email1

本實驗以ubuntu22.04為例,郵件服務器mxout.XXX.com可以匿名訪問,所以不需要配置賬號名和密碼

root@FDB001:~# systemctl status sendmail
Unit sendmail.service could not be found.
root@FDB001:~#
root@FDB001:~# ll /etc/mail
ls: cannot access '/etc/mail': No such file or directory
root@FDB001:~#
root@FDB001:~# ll /usr/lib/systemd/system |grep mail
root@FDB001:~# apt-get install sendmail
root@FDB001:~#
root@FDB001:~# systemctl status sendmail
● sendmail.service - LSB: powerful, efficient, and scalable Mail Transport AgentLoaded: loaded (/etc/init.d/sendmail; generated)Active: active (running) since Tue 2024-07-02 03:22:09 UTC; 1min 21s agoDocs: man:systemd-sysv-generator(8)Tasks: 1 (limit: 9388)Memory: 2.9MCPU: 81msCGroup: /system.slice/sendmail.service└─199151 "sendmail: MTA: accepting connections" "" "" "" "" "" "" "" "" "" ""
Jul 02 03:22:07 FDB001 systemd[1]: Starting LSB: powerful, efficient, and scalable Mail Transport Agent...
Jul 02 03:22:07 FDB001 sendmail[199102]:  * Starting Mail Transport Agent (MTA) sendmail
Jul 02 03:22:07 FDB001 sendmail[199122]: hostname: Temporary failure in name resolution
Jul 02 03:22:07 FDB001 sendmail[199127]: hostname: Temporary failure in name resolution
Jul 02 03:22:07 FDB001 su[199136]: (to smmsp) root on none
Jul 02 03:22:07 FDB001 su[199136]: pam_unix(su:session): session opened for user smmsp(uid=116) by (uid=0)
Jul 02 03:22:07 FDB001 su[199136]: pam_unix(su:session): session closed for user smmsp
Jul 02 03:22:07 FDB001 sm-mta[199151]: starting daemon (8.15.2): SMTP+queueing@00:10:00
Jul 02 03:22:09 FDB001 sendmail[199102]:    ...done.
Jul 02 03:22:09 FDB001 systemd[1]: Started LSB: powerful, efficient, and scalable Mail Transport Agent.
root@FDB001:~#
root@FDB001:~# ll /etc/mail
total 228
drwxr-sr-x   7 smmta smmsp  4096 Jul  2 03:22 ./
drwxr-xr-x 112 root  root   4096 Jul  2 03:22 ../
-rw-------   1 root  root   4265 Jul  2 03:22 access
-rw-r-----   1 smmta smmsp 12288 Jul  2 03:22 access.db
-rw-r--r--   1 root  root    281 Dec  9  2021 address.resolve
lrwxrwxrwx   1 root  smmsp    10 Jul  2 03:22 aliases -> ../aliases
-rw-r-----   1 smmta smmsp 12288 Jul  2 03:22 aliases.db
-rw-r--r--   1 root  root   3226 Jul  2 03:22 databases
-rw-r--r--   1 root  root   5659 Dec  9  2021 helpfile
-rw-r--r--   1 root  smmsp    11 Jul  2 03:22 local-host-names
drwxr-sr-x   2 smmta smmsp  4096 Jul  2 03:22 m4/
-rwxr-xr--   1 root  smmsp 10019 Jul  2 03:22 Makefile*
drwxr-xr-x   2 root  root   4096 Jul  2 03:22 peers/
drwxr-xr-x   2 root  smmsp  4096 Dec  9  2021 sasl/
-rw-r--r--   1 root  smmsp 64130 Jul  2 03:22 sendmail.cf
-rw-r--r--   1 root  root  12235 Jul  2 03:22 sendmail.conf
-rw-r--r--   1 root  smmsp  4066 Jul  2 03:22 sendmail.mc
-rw-r--r--   1 root  root    148 Dec  9  2021 service.switch
-rw-r--r--   1 root  root    179 Dec  9  2021 service.switch-nodns
drwxr-sr-x   2 smmta smmsp  4096 Jul  2 03:22 smrsh/
-rw-r--r--   1 root  smmsp 44563 Jul  2 03:22 submit.cf
-rw-r--r--   1 root  smmsp  2383 Jul  2 03:22 submit.mc
drwxr-xr-x   2 root  smmsp  4096 Dec  9  2021 tls/
-rw-r--r--   1 root  smmsp     0 Jul  2 03:22 trusted-users
root@FDB001:~#
root@FDB001:~# ll /usr/lib/systemd/system |grep mail
root@FDB001:~#
root@FDB001:~# systemctl list-unit-files |grep mail
sendmail.service                           generated       -
root@FDB001:~#
root@FDB001:~# systemctl list-dependencies sendmail --reverse
sendmail.service
● ├─graphical.target
● └─multi-user.target
●   └─graphical.target
root@FDB001:~#
root@FDB001:~# service sendmail status
● sendmail.service - LSB: powerful, efficient, and scalable Mail Transport AgentLoaded: loaded (/etc/init.d/sendmail; generated)Active: active (running) since Tue 2024-07-02 03:22:09 UTC; 23min agoDocs: man:systemd-sysv-generator(8)Tasks: 1 (limit: 9388)Memory: 3.6MCPU: 147msCGroup: /system.slice/sendmail.service└─199151 "sendmail: MTA: accepting connections" "" "" "" "" "" "" "" "" "" ""
Jul 02 03:22:07 FDB001 su[199136]: (to smmsp) root on none
Jul 02 03:22:07 FDB001 su[199136]: pam_unix(su:session): session opened for user smmsp(uid=116)>
Jul 02 03:22:07 FDB001 su[199136]: pam_unix(su:session): session closed for user smmsp
Jul 02 03:22:07 FDB001 sm-mta[199151]: starting daemon (8.15.2): SMTP+queueing@00:10:00
Jul 02 03:22:09 FDB001 sendmail[199102]:    ...done.
Jul 02 03:22:09 FDB001 systemd[1]: Started LSB: powerful, efficient, and scalable Mail Transpor>
Jul 02 03:37:17 FDB001 sm-mta[200089]: 4623bHbK200089: from=<root@FDB001>, size=452, class>
Jul 02 03:37:18 FDB001 sm-mta[200090]: 4623bHbK200089: to=<root@FDB001>, ctladdr=<root@FRS>
Jul 02 03:37:18 FDB001 sm-mta[200092]: 4623bI5I200092: from=<root@FDB001>, size=448, class>
Jul 02 03:37:18 FDB001 sm-mta[200093]: 4623bI5I200092: to=<root@FDB001>, ctladdr=<root@FRS>
root@FDB001:~#
root@FDB001:~# (echo From: "WON Notification <notification@XXX.com>";echo To: "lukes.liao@XXXchina.com";echo Subject: "This is test1";echo "The Content is just a test email1")| /usr/sbin/sendmail -t
--還是收不到郵件,且service sendmail status看不到任何報錯信息
root@FDB001:~#
root@FDB001:~# apt-get install m4 sendmail-cf
root@FDB001:~# grep SMART_HOST /etc/mail/sendmail.mc
define(`SMART_HOST', `mxout.XXX.com')
root@FDB001:~# cd /etc/mail
root@FDB001:~# m4 sendmail.mc >sendmail.cf
root@FDB001:~#
root@FDB001:~# service sendmail restart
root@FDB001:~# 
root@FDB001:~# (echo From: "WON Notification <notification@XXX.com>";echo To: "lukes.liao@XXXchina.com";echo To: "lukes.liao2@XXXchina.com";echo Subject: "This is test1";echo "The Content is just a test email1")| /usr/sbin/sendmail -t
--收不到郵件,但是service sendmail status看有報錯DSN: Service unavailable
root@FDB001:~# vim /etc/hosts
127.0.0.1 FDB001 FDB001.dai.netdai.com
--加上FDB001.dai.netdai.com
root@FDB001:~# vim /etc/hostname
FDB001.dai.netdai.com
--加上.dai.netdai.com
root@FDB001:~# 
root@FDB001:~# cat /root/emailtest.txt
From: WON Notification <notification@XXX.com>
To: lukes.liao@XXXchina.com
To: lukes.liao2@XXXchina.com
Subject: "This is test1"
The Content is just a test email1
root@FDB001:~#
root@FDB001:~# sendmail -t </root/emailtest.txt

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/diannao/43078.shtml
繁體地址,請注明出處:http://hk.pswp.cn/diannao/43078.shtml
英文地址,請注明出處:http://en.pswp.cn/diannao/43078.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

HTTP 請求走私漏洞詳解

超詳細的HTTP請求走私漏洞教程&#xff0c;看完還不會你來找我。 1. 簡介 HTTP請求走私漏洞&#xff08;HTTP Request Smuggling&#xff09;發生在前端服務器&#xff08;也稱代理服務器&#xff0c;一般會進行身份驗證或訪問控制&#xff09;和后端服務器在解析HTTP請求時&…

上位機圖像處理和嵌入式模塊部署(mcu項目2:串口日志記錄器)

【 聲明&#xff1a;版權所有&#xff0c;歡迎轉載&#xff0c;請勿用于商業用途。 聯系信箱&#xff1a;feixiaoxing 163.com】 淘寶上面有一個商品蠻好玩的&#xff0c;那就是日志記錄器。說是記錄器&#xff0c;其實就是一個模塊&#xff0c;這個模塊的輸入是一個ttl串口&am…

利用Python進行數據分析PDF下載經典數據分享推薦

本書由Python pandas項目創始人Wes McKinney親筆撰寫&#xff0c;詳細介紹利用Python進行操作、處理、清洗和規整數據等方面的具體細節和基本要點。第2版針對Python 3.6進行全面修訂和更新&#xff0c;涵蓋新版的pandas、NumPy、IPython和Jupyter&#xff0c;并增加大量實際案例…

Docker Desktop如何換鏡像源?

docker現在很多鏡像源都出現了問題,導致無法拉取鏡像,所以找到一個好的鏡像源,尤為重要。 一、阿里鏡像源 經過測試,目前,阿里云鏡像加速地址還可以使用。如果沒有阿里云賬號,需要先注冊一個賬號。 地址:https://cr.console.aliyun.com/cn-hangzhou/instances/mirrors 二…

基于Java技術的B/S模式書籍學習平臺

你好&#xff0c;我是專注于計算機科學領域的學姐碼農小野。如果你對書籍學習平臺開發感興趣或有相關需求&#xff0c;歡迎私信聯系我。 開發語言&#xff1a; Java 數據庫&#xff1a; MySQL 技術&#xff1a; B/S模式、Java技術 工具&#xff1a; Eclipse、Navicat、Mave…

【Go】函數的使用

目錄 函數返回多個值 init函數和import init函數 main函數 函數的參數 值傳遞 引用傳遞&#xff08;指針&#xff09; 函數返回多個值 用法如下&#xff1a; package mainimport ("fmt""strconv" )// 返回多個返回值&#xff0c;無參數名 func Mu…

相鄰不同數字的標記

鏈接&#xff1a;登錄—專業IT筆試面試備考平臺_牛客網 來源&#xff1a;牛客網 時間限制&#xff1a;C/C 1秒&#xff0c;其他語言2秒 空間限制&#xff1a;C/C 262144K&#xff0c;其他語言524288K 64bit IO Format: %lld 題目描述 小紅拿到了一個數組&#xff0c;每個數…

ctfshow web入門 nodejs web334--web337

web334 有個文件下載之后改后綴為zip加壓就可以得到兩個文件 一個文件類似于index.php 還有一個就是登錄密碼登錄成功就有flag username:ctfshow password:123456因為 return name!CTFSHOW && item.username name.toUpperCase() && item.password passwor…

SpringBoot的熱部署和日志體系

SpringBoot的熱部署 每次修改完代碼&#xff0c;想看效果的話&#xff0c;不用每次都重新啟動代碼&#xff0c;等待項目重啟 這樣就可以了 JDK官方提出的日志框架&#xff1a;Jul log4j的使用方式&#xff1a; &#xff08;1&#xff09;引入maven依賴 &#xff08;2&#x…

軟件開發語言都有哪些?

構建高效、穩定且安全的服務器應用&#xff0c;開發者們需要選擇合適的編程語言。以下是幾種流行的網絡服務器開發語言&#xff0c;每種語言都有其獨特的特性和適用場景。 Java Java是一種廣泛使用的高級編程語言&#xff0c;以其“一次編寫&#xff0c;到處運行”的理念而著稱…

光譜優化算法(Lightning Search Optimization, LSO)及其Python和MATLAB實現

光譜優化算法&#xff08;Lightning Search Optimization, LSO&#xff09;是一種基于自然界雷暴現象啟發的新型優化算法&#xff0c;旨在尋找最優解或近似最優解的問題。LSO算法不僅可以用于連續優化問題&#xff0c;還能用于離散優化問題。接下來將詳細介紹LSO算法的背景、原…

內鏡像源-大全

1、pip安裝鏡像 阿里鏡像 https://developer.aliyun.com/mirror/ 清華大學開源軟件鏡像 https://mirrors.tuna.tsinghua.edu.cn/ 浙大鏡像源 http://mirrors.zju.edu.cn/ 網易鏡像源 https://mirrors.163.com/ sohu鏡像源 https://mirrors.sohu.com/ 中科大鏡像 https://mirr…

OS Copilot測評-CSDN

登錄控制臺 安裝插件 sudo yum install -y os-copilot效果如下 配置 AccessKey ID 與 AccessKey Secret 注意安全&#xff0c;使用完成后&#xff0c;別忘了去控制臺刪除&#xff0c;一般情況使用子Key就可以 檢測是否可用 co hi實際操作(當前為官方案例請求) 實操1&…

RoPE 旋轉位置編碼,詳細解釋(下)NLP 面試的女生徹底說明白了

RoPE 旋轉位置編碼&#xff0c;詳細解釋&#xff08;下&#xff09;NLP 面試的女生徹底說明白了 原創 看圖學 看圖學 2024年07月01日 07:55 北京 書接上文&#xff0c;上文見&#xff1a;這么解釋 RoPE 旋轉位置編碼&#xff0c;女朋友睜大了雙眼&#xff08;上&#xff09; …

C++ explicit 用法

一、概述 explicit關鍵字用于防止構造函數或轉換操作符在不明確的情況下被隱式調用&#xff0c;從而避免意外的類型轉換。這在類的設計中非常有用&#xff0c;可以增強代碼的可讀性和安全性。 二、用法示例 1. 用于構造函數 假設有一個簡單的類 A&#xff1a; class A { p…

metersphere鏈接騰訊郵箱步驟

1、打開騰訊郵箱生成授權碼 路徑&#xff1a;設置-賬戶-賬戶安全 生成的授權碼只會展示1次&#xff0c;注意保存 2、在系統設置-系統參數設置-郵件設置填寫授權碼和SMTP信息 SMTP信息在郵箱的客戶端設置中可以獲取到對應的信息 3、信息填寫完后&#xff0c;可以測試連接&…

python中TensorFlow框架的簡單深度學習項目圖像分類示例

??引言 &#x1f44d;&#x1f44d;點關注編程夢想家&#xff08;大學生版&#xff09;-CSDN博客不迷路?? 這個示例項目使用了CIFAR-10數據集&#xff0c;這是一個包含10個類別的60,000張32x32彩色圖像的數據集&#xff0c;類別包括飛機、汽車、鳥類等。模型是一個簡單的…

Pytest單元測試系列[v1.0.0][高級技巧]

playwright結合pytest使用 安裝配置環境 PS D:\Programs\Python\com.davieyang.demo> pip install pytest-playwright Collecting pytest-playwrightDownloading pytest_playwright-0.3.0-py3-none-any.whl (10 kB) Requirement already satisfied: pytest in c:\program …

集成sa-token前后端分離部署配置corsFliter解決跨域失效的真正原因

文章目錄 1.前言2.問題復現3.解決方法3.1 方式一&#xff1a;后端修改CorsFilter源碼3.2 方式二&#xff1a;前端禁用或移除瀏覽器referrer-policy引用者策略 4.總結 1.前言 緣由請參看下面這篇文章&#xff1a;sa-token前后端分離解決跨域的正確姿勢 https://mp.weixin.qq.co…

桌面記筆記的軟件:能加密的筆記app

在日常生活和工作中&#xff0c;很多人都有記筆記的習慣。無論是記錄會議要點、學習心得&#xff0c;還是生活中的點滴靈感&#xff0c;筆記都是我們不可或缺的好幫手。然而&#xff0c;傳統的紙筆記錄方式逐漸不能滿足現代人的需求&#xff0c;因為紙質筆記不易保存、查找困難…