一行从linux终端发送邮件 [英] send mail from linux terminal in one line

查看:28
本文介绍了一行从linux终端发送邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道 Linux 中有 mail 命令可以通过命令行发送电子邮件.但是,如何从终端用一行发送简单的电子邮件?

I know there is the command mail in linux to send emails via command line. How can I send an simple email with one line from the terminal though?

例如:

mail user@gmail.com [subject] [body]

是否在没有任何确认或提示的情况下向用户发送了电子邮件?

And have the email sent without any confirmation or prompts to the user?

原因是,当java 程序中发生特定事件时,我想通过电子邮件向自己发送一条简短的消息.这个想法是我将使用 Runtime.getRuntime()... 等从我的 java 程序发送 mail 命令.

The reason is, I want to send a brief message via email to myself when a specific event happens in a java program. The idea is that I will use Runtime.getRuntime()… etc. to send the mail command from my java program.

我过去使用 cron 做了类似的事情,但当前的实现没有使用 cron,所以我需要试试这个.

I used cron to do something similar in the past, but the current implementation doesn't use cron, so I need to try this out instead.

推荐答案

ma​​il 可以代表 Linux 系统上的许多程序.您想要的是sendmailpostfix.我推荐后者.

mail can represent quite a couple of programs on a linux system. What you want behind it is either sendmail or postfix. I recommend the latter.

您可以通过您喜欢的包管理器安装它.然后你必须配置它,完成后,你可以像这样发送电子邮件:

You can install it via your favorite package manager. Then you have to configure it, and once you have done that, you can send email like this:

 echo "My message" | mail -s subject user@gmail.com

有关详细信息,请参阅手册.

See the manual for more information.

就配置 postfix 而言,互联网上有很多关于如何配置的文章.除非您在具有注册域的公共服务器上,否则您通常希望将电子邮件转发到可以从中发送电子邮件的 SMTP 服务器.

As far as configuring postfix goes, there's plenty of articles on the internet on how to do it. Unless you're on a public server with a registered domain, you generally want to forward the email to a SMTP server that you can send email from.

例如,对于 gmail,请遵循http://rtcamp.com/tutorials/linux/ubuntu-postfix-gmail-smtp/或任何其他类似的教程.

For gmail, for example, follow http://rtcamp.com/tutorials/linux/ubuntu-postfix-gmail-smtp/ or any other similar tutorial.

这篇关于一行从linux终端发送邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆