AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / ubuntu / 问题 / 1332219
Accepted
sancho.s ReinstateMonicaCellio
sancho.s ReinstateMonicaCellio
Asked: 2021-04-19 05:21:28 +0800 CST2021-04-19 05:21:28 +0800 CST 2021-04-19 05:21:28 +0800 CST

通过 gmail 发送电子邮件,无需其他邮件服务器,带有后缀

  • 772

我在配置邮件系统方面缺乏经验。我正在使用 Ubuntu #54~20.04.1-Ubuntu。

如何配置我的计算机以使用 gmail 帐户发送电子邮件postfix?
我的意思是不涉及任何其他付费邮件服务器或域(编辑:我可以将我的 PC 配置为服务器,但我的意思是避免要求在 DNS 中进行付费注册)。 这甚至可能吗?

我尝试了一些东西,我将在下面描述,引用我使用的来源。
我已经阅读了其他资料,但我不知道该怎么做。据我了解,这些其他来源中的大多数都假设我有一些其他可以使用的服务器或地址(通常示例为example.com),但我没有,我想我可以省去。

  1. 我遵循了这个基本指南,这似乎对许多其他人有用。发出后

    echo "Test mail thingy" | mail -s "Test Postfix Subject" [email protected]
    

    我没有收到电子邮件[email protected],这是/var/log/mail.log(添加行号以供参考)的相关尾部

     1 Apr 18 08:55:03 MyComputer postfix/postfix-script[1092678]: refreshing the Postfix mail system
     2 Apr 18 08:55:03 MyComputer postfix/master[3124]: reload -- version 3.4.13, configuration /etc/postfix
     3 Apr 18 08:55:24 MyComputer postfix/pickup[1092682]: 06004443921: uid=1000 from=<MyUser@MyComputer>
     4 Apr 18 08:55:24 MyComputer postfix/cleanup[1092704]: 06004443921: message-id=<[email protected]_URL>
     5 Apr 18 08:55:24 MyComputer postfix/qmgr[1092683]: 06004443921: from=<MyUser@MyComputer>, size=391, nrcpt=1 (queue active)
     6 Apr 18 08:55:24 MyComputer postfix/error[1092706]: 06004443921: to=<[email protected]>, relay=none, delay=0.03, delays=0.02/0/0/0.01, dsn=5.0.0, status=bounced ([smtp.gmail.com]:587)
     7 Apr 18 08:55:24 MyComputer postfix/cleanup[1092704]: 09DD4443938: message-id=<[email protected]_URL>
     8 Apr 18 08:55:24 MyComputer postfix/bounce[1092707]: 06004443921: sender non-delivery notification: 09DD4443938
     9 Apr 18 08:55:24 MyComputer postfix/qmgr[1092683]: 09DD4443938: from=<>, size=2359, nrcpt=1 (queue active)
    10 Apr 18 08:55:24 MyComputer postfix/qmgr[1092683]: 06004443921: removed
    11 Apr 18 08:55:24 MyComputer postfix/local[1092708]: 09DD4443938: to=<MyUser@MyComputer>, relay=local, delay=0.01, delays=0/0/0/0, dsn=2.0.0, status=sent (delivered to mailbox)
    12 Apr 18 08:55:24 MyComputer postfix/qmgr[1092683]: 09DD4443938: removed
    

    我不知道如何解释这个日志。我注意到第 11 行状态status=sent。

  2. 我添加了-a "From: [email protected]"(参考)。我也没有收到邮件。/var/log/mail.log与上述相比发生变化的行标有*。现在我status=bounced在第 11 行。

     3*Apr 18 09:54:43 MyComputer postfix/pickup[1098199]: 0353244348F: uid=1000 from=<[email protected]>   <-- CHANGED
     4 Apr 18 09:54:43 MyComputer postfix/cleanup[1098387]: 0353244348F: message-id=<[email protected]_URL>
     5*Apr 18 09:54:43 MyComputer postfix/qmgr[1098200]: 0353244348F: from=<[email protected]>, size=384, nrcpt=1 (queue active)   <-- CHANGED
     6 Apr 18 09:54:43 MyComputer postfix/error[1098389]: 0353244348F: to=<[email protected]>, relay=none, delay=0.03, delays=0.02/0/0/0, dsn=5.0.0, status=bounced ([smtp.gmail.com]:587)
     7 Apr 18 09:54:43 MyComputer postfix/cleanup[1098387]: 06E2F4436C3: message-id=<[email protected]_URL>
     8 Apr 18 09:54:43 MyComputer postfix/bounce[1098390]: 0353244348F: sender non-delivery notification: 06E2F4436C3
     9 Apr 18 09:54:43 MyComputer postfix/qmgr[1098200]: 06E2F4436C3: from=<>, size=2364, nrcpt=1 (queue active)
    10 Apr 18 09:54:43 MyComputer postfix/qmgr[1098200]: 0353244348F: removed
    11*Apr 18 09:54:43 MyComputer postfix/error[1098389]: 06E2F4436C3: to=<[email protected]>, relay=none, delay=0.01, delays=0/0/0/0, dsn=5.0.0, status=bounced ([smtp.gmail.com]:587)   <-- CHANGED
    12 Apr 18 09:54:43 MyComputer postfix/qmgr[1098200]: 06E2F4436C3: removed
    

笔记:

  1. 在我今天尝试之前,我已经安装了 postfix。我不记得我何时以及为什么安装它。我不记得通过后缀配置屏幕。我知道我可以做到这一点,sudo dpkg-reconfigure postfix但我不知道哪个是正确的选择。

  2. 这增加smtp_tls_CAfile = /etc/postfix/cacert.pem了/etc/postfix/main.cf,而不是smtp_tls_CApath ...,后来catsa 特定.pem于cacert.pem。我没有cacert.pem。我想如果配置正确,这两个选项都可以工作。

  3. 我有很多软链接/etc/ssl/certs/。我不确定我需要添加任何东西。

  4. 我使用了我的实际来源 gmail 和相应的密码/etc/postfix/sasl_passwd。

相关:

  1. 如何配置 postfix 以通过 gmail 发送电子邮件(2FA 问题)?
  2. SETUP 通过后缀发送邮件到 GMAIL 以使用ssmtp而不是postfix.
  3. 将 gmail 设置为使用 gnome-gmail 或 desktop-webmail通过电子邮件发送文件的默认值。
  4. https://rtcamp.com/tutorials/linux/ubuntu-postfix-gmail-smtp/
  5. 从 Gmail 帐户发送电子邮件到本地 Ubuntu 服务器
  6. Ubuntu 20.04 邮件设置设置默认发件人地址
  7. https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-postfix-as-a-send-only-smtp-server-on-ubuntu-18-04
  8. https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-postfix-on-ubuntu-20-04
  9. https://www.linuxbabe.com/mail-server/setup-basic-postfix-mail-sever-ubuntu
  10. https://www.cyberciti.biz/faq/how-to-configure-postfix-relayhost-smarthost-to-send-email-using-an-external-smptd/
  11. https://ubuntu.com/server/docs/mail-postfix
  12. https://devops.ionos.com/tutorials/configure-a-postfix-relay-through-gmail-on-ubuntu/
email
  • 2 2 个回答
  • 1989 Views

2 个回答

  • Voted
  1. Best Answer
    sancho.s ReinstateMonicaCellio
    2021-04-19T18:40:23+08:002021-04-19T18:40:23+08:00

    postfix通过 Gmail发送电子邮件的分步指南。

    我终于设法通过 Gmail发送电子邮件。Raffa ( 1 , 2 ) 的两个回答和进一步的评论对我帮助很大。但是仍然需要进一步的研究和修补。

    在这里,(希望)完整的指南。

    1. 安装postfix和其他软件包。

      $ sudo apt-get install postfix mailutils libsasl2-2 ca-certificates libsasl2-modules
      
    2. 将显示安装后的配置。如果没有,请使用$ sudo dpkg-reconfigure postfix. 对于连续的屏幕,使用:1. 卫星系统,2. MyServer(替换为您的服务器名称),3. [smtp.gmail.com]:587,4. root,5 和以下:保留默认值。

    3. 使您的 gmail 帐户能够与postfix. 有两种选择。

      4.1。(首选、更安全的方法)如果尚未激活,请在您的 Google 帐户中激活两步验证。然后为 Postfix 生成一个App 密码。稍后您将需要此密码。

      4.2. 如果不使用两步验证,请启用安全性较低的应用。

    4. 将以下行添加到/etc/postfix/main.cf

      relayhost = [smtp.gmail.com]:587
      smtp_sasl_auth_enable = yes
      smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
      smtp_sasl_security_options = 
      smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt
      smtp_use_tls = yes
      
    5. 创建/编辑/etc/postfix/sasl_passwd,使其包含

      [smtp.gmail.com]:587    [email protected]:<password>
      

      <password>如果不使用两步验证,则应替换为帐户密码,否则应替换为生成的应用程序密码。

    6. 使用以下命令

      $ sudo chmod 600 /etc/postfix/sasl_passwd
      $ sudo postmap /etc/postfix/sasl_passwd
      $ sudo systemctl restart postfix.service
      
    7. 发送电子邮件

      $ echo "This is the body of an encrypted email" | mail -s "This is the subject line" [email protected]
      
    • 2
  2. Raffa
    2021-04-19T10:11:52+08:002021-04-19T10:11:52+08:00

    看来您没有使用中继电子邮件/主机,并且您正在尝试直接从您的机器发送电子邮件,正如您所解释的那样,它没有合格的域名......更不用说其他要求,如反向 DNS 记录和 MX 记录。

    在您的日志中很清楚没有使用有效的中继:

    中继=本地

    和

    中继=无

    您想知道为什么您的电子邮件会反弹!

    无论您做什么,它们都会永远反弹。

    • 域名是具有常见 TLD 的名称,例如 example.com、example.net... 等,必须绑定到您的发送计算机的 IP... 您需要这个。

    • 机器的发送 IP还必须通过反向 DNS 记录绑定到发送域名,该反向 DNS 记录只能由您的 ISP(为您提供 IP 地址的公司)添加

    • MX 记录是另一种类型的 DNS 记录,它告诉电子邮件服务器/提供商将您的电子邮件消息路由到哪里……您也需要这个。

    这些是现代电子邮件提供商接受来自您的计算机的电子邮件的要求……否则这些电子邮件将被退回/拒绝。

    如果您愿意走这条路并成为您自己的电子邮件提供商,那么您现在知道该做什么了。

    否则,请使用继电器......请参阅此答案以获取说明。

    • 1

相关问题

  • 如何让 Evolution 自动应用过滤器?

  • 电脑残障人士的电邮申请

  • 在 Kmail 中配置 GPG

  • 如何在不保持主 UI 打开的情况下进行 Evolution 检查并通知新电子邮件?[关闭]

  • 如何配置邮件服务器以报告与服务器名称不同的主机名[关闭]

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何运行 .sh 脚本?

    • 16 个回答
  • Marko Smith

    如何安装 .tar.gz(或 .tar.bz2)文件?

    • 14 个回答
  • Marko Smith

    如何列出所有已安装的软件包

    • 24 个回答
  • Marko Smith

    无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗?

    • 25 个回答
  • Martin Hope
    Flimm 如何在没有 sudo 的情况下使用 docker? 2014-06-07 00:17:43 +0800 CST
  • Martin Hope
    Ivan 如何列出所有已安装的软件包 2010-12-17 18:08:49 +0800 CST
  • Martin Hope
    La Ode Adam Saputra 无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗? 2010-11-30 18:12:48 +0800 CST
  • Martin Hope
    David Barry 如何从命令行确定目录(文件夹)的总大小? 2010-08-06 10:20:23 +0800 CST
  • Martin Hope
    jfoucher “以下软件包已被保留:”为什么以及如何解决? 2010-08-01 13:59:22 +0800 CST
  • Martin Hope
    David Ashford 如何删除 PPA? 2010-07-30 01:09:42 +0800 CST

热门标签

10.10 10.04 gnome networking server command-line package-management software-recommendation sound xorg

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve