简体   繁体   English

Unix的邮件命令

[英]mail command of unix

I am using the mail command of unix in a perl script. 我在perl脚本中使用unix的mail命令。 I specify the 'to', 'cc', 'subject' and 'body' of the mail. 我指定邮件的“收件人”,“抄送”,“主题”和“正文”。 I do not specify the from address. 我没有指定发件人地址。 Where is the from address picked from? 发件人地址是从哪里选的? Pls help 请帮助

There are portable libraries for handling email as daxim and David W mention, but if you want a quick fix, this works under linux if your mail command uses bsd-mailx (as it does on my machine)... 有可移植的库,用于处理daxim和David W提到的电子邮件,但是,如果您想要快速修复,那么如果您的mail命令使用bsd-mailx (在我的机器上也是如此),则可以在linux下使用...

#!/usr/bin/env perl

$BODY = "Hello self";
$RECIPIENT = "destination\@email.local";
$FROM = "mike\@localhost";
$SUBJECT = "some subject here";
$CMD = qq(echo "$BODY" | mail -a "From: $FROM" -s $SUBJECT $RECIPIENT);
exec($CMD);

If you have more questions about the unix mail command, try man mail from your shell prompt. 如果您对unix mail命令有更多疑问,请在shell提示符下尝试man mail

The mail command on most system nowadays is Heirloom mailx . 如今,大多数系统上的mail命令都是Heirloom mailx It claims compatibility with POSIX, so the information I give here should be good for any well-behaving mail command. 它声称与POSIX兼容,因此我在这里提供的信息对于任何运行良好的mail命令都应该是有用的。

The From address is set by: From地址设置为:

  • either the user@domain as returned by the appropriate POSIX system calls (see shell commands whoami and domainname -f for a different way to access them) 适当的POSIX系统调用返回的user@domain (有关访问它们的不同方法,请参见shell命令whoamidomainname -f
  • or set by the from environment variable 或由from环境变量设置
  • or set by the -r command line option (going to be deprecated?) 或由-r命令行选项设置(是否要弃用?)

Obligatory Clippy: Hi! 必修:你好! I see you are trying to send mail from Perl . 我看到您正在尝试从Perl发送邮件 Did you mean to use Email::Sender / Email::Simple instead? 您是否要改为使用Email ::发件人 / Email ::简单

Don't use the mail command linecommand! 不要使用mail命令行命令! Use Net::SMTP . 使用Net :: SMTP

The mail command may not even be configured on a particular system, and it won't work on Windows. mail命令甚至可能没有在特定系统上配置,并且在Windows上无法使用。 Meanwhile, Net::SMTP is a standard Perl module that should be available on all systems. 同时, Net::SMTP是标准的Perl模块,应该在所有系统上都可用。

Never used it before? 以前没用过? Read the documentation and try it out. 阅读文档并尝试一下。 That's how you learn. 那就是你学习的方式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM