如何从命令行发送邮件?

如何从命令行发送邮件?

尝试安装Mutt电子邮件客户端 。 其他选项是使用带有gnus的 emacs。 其他选项也可用…恕我直言,您应该在问题中使用更多详细信息,或者您将收到的问题的几个不同答案:-)

  1. 安装ssmtp 安装ssmtp

    sudo apt-get install ssmtp 
  2. 编辑ssmtp配置文件:

     gksu gedit /etc/ssmtp/ssmtp.conf 
  3. 附加以下文字:

     root=username@gmail.com mailhub=smtp.gmail.com:465 rewriteDomain=gmail.com AuthUser=username AuthPass=password FromLineOverride=YES UseTLS=YES 
  4. 运行ssmtp并提供收件人电子邮件地址:

     ssmtp recepient_name@gmail.com 
  5. 提供消息详细信息如下:

     To: recipient_name@gmail.com From: username@gmail.com Subject: Sent from a terminal! Your content goes here. Lorem ipsum dolor sit amet, consectetur adipisicing. (Notice the blank space between the subject and the body.) 
  6. Ctrl + D发送。


您也可以将文本放在文件中并按如下方式发送:

 ssmtp recipient_name@gmail.com < filename.txt 

大多数情况下,您不需要配置SMTP服务器,只需使用命令行中的mail (如果它尚未存在,请使用sudo apt-get install mailutils )。 (或者,如果您在配置了sendmail的服务器上,等等)

 marco@dagobah:~$ mail -v marco.ceppi.use@gmail.com Subject: Hello World! This is an email to myself. Hope all is well. . Cc: 

您使用单个邮件终止邮件. 在线。 那时mail将提示您输入Cc:输入信息(或留空), mail将打印出有关其尝试的信息的附加信息,以及详细说明从邮件中连接,传输和接收数据的处理服务器。

 apt-get install libio-socket-ssl-perl libnet-ssleay-perl sendemail 

用法:

 sendemail -f fromuser@gmail.com -t touser@domain.com -u subject -m "message" -s smtp.gmail.com:587 -o tls=yes -xu gmailaccount@gmail.com -xp gmailpassword 

如果您不想在命令行中指定密码(通常不是一件好事),您可以省略该参数,sendemail会提示您输入密码……并将其显示在屏幕上,但至少它不会出现在命令行历史记录中。

mpack是发送文件附件的极佳命令行方式。

 apt-get install mpack 

用法:

 mpack -s "file you wanted" ./data.pdf loser@supergoober.cn 

您需要MTA才能发送邮件。 为此,请使用后缀:

 sudo apt-get install postfix 

发送电子邮件:

 echo "test message" | mailx -s 'test subject' myemail@mydomain.com 

救命

安装包sendmail然后键入

 sendmail -t receiver@example 

然后写下你的电子邮件,然后按Ctrl + D.

您可以使用TelNetNetCat从命令行发送电子邮件。

这里解释一切。

 hanoo@hp_laptop% nc 127.0.0.1 25 220 hp_laptop.localdomain ESMTP Postfix EHLO man 250 hp_laptop.localdomain MAIL FROM:  250 2.1.0 Ok RCPT TO:  250 2.1.5 Ok data 354 End data with . This is the body of my mail, this is the second line... . 250 2.0.0 Ok: queued as 9C12E7F404 
 mail -s "subjet" -a "attchedfile_name" someone@dest_email.com 

要么

 cat "afile" | mail -s "subject" someone@dest_email.com 

如果您尝试从系统发送电子邮件,whitch不运行自己的电子邮件服务器(即桌面系统),则需要安装nullmailer或esmtp之类的东西,将您的本地邮件转发为“真实”邮件服务器。

作为命令行工具,您可以安装mail或mailx(包mailutils,heirloom-mailx或bsd-mailx)。 如果你需要附件,请尝试biabam。

我从未尝试过,但有一个mail命令可以发送邮件。 见男子邮件 。

要测试本地电子邮件:

 echo message | mail username@localhost 
 sudo apt-get install sharutils mailutils uuencode filename filename | mail user@example.com 

其中filename是相同的:它代表输入文件和远程文件。

你可以试试这个:

 mail name@mailserver.com -s "Attached file" < 

它适用于GNU Mailutils ,请访问网站以获取更多信息。

运行

 sudo apt-get install ssmtp sudo -H gedit /etc/ssmtp/ssmtp.conf 

需要在此处添加以下内容:

 # The user that gets all the mails (UID < 1000, usually the admin) root=yourusernameofgmail@gmail.com # The mail server (where the mail is sent to), both port 465 or 587 should be acceptable # See also https://support.google.com/mail/answer/78799 mailhub=smtp.gmail.com:587 # The address where the mail appears to come from for user authentication. rewriteDomain=gmail.com # Use SSL/TLS before starting negotiation UseTLS=Yes UseSTARTTLS=Yes # Username/Password AuthUser=yourusernameofgmail AuthPass=yourGmailPassowrd AuthMethod=LOGIN # Email 'From header's can override the default domain? FromLineOverride=yes 

运行

 sudo -H gedit /etc/ssmtp/revaliases 

进入那里:

 root:yourusernameofgmail@gmail.com:smtp.gmail.com:587 

在Gmail上启用“安全性较低的应用”
https://support.google.com/accounts/answer/6010255?hl=en

通过在终端上运行以下命令来测试它:

 echo "Body of mail is abc" | mail -s "Subject is xyz" "someusername@gmail.com"` 

除了上面我还是得到了这个错误

 echo "Test message from Linux server using ssmtp" | sudo ssmtp -vvv somebody@mil.gov [<-] 220 smtp.gmail.com ESMTP v193sm19198825qka.18 - gsmtp [->] EHLO localhost [<-] 250 SMTPUTF8 [->] STARTTLS [<-] 220 2.0.0 Ready to start TLS [->] EHLO localhost [<-] 250 SMTPUTF8 [->] AUTH LOGIN [<-] 334 VXNlcm5hbWU6 [->] aG94Z2VuZUBrrrFpbC5jb20= [<-] 334 UGFzweliecmQ6 [<-] 534 5.7.14 https://support.google.com/mail/answer/78754 v193sm19198825qka.18 - gsmtp ssmtp: Authorization failed (534 5.7.14 https://support.google.com/mail/answer/78754 v193sm19198825qka.18 - gsmtp) 

解决方案:即使当前密码正确,也要重置Gmail密码...可能是Google安全预防措施