[英]Mailx from within a C program?
I'm hoping to send a message via mailx to a list of recipients from within my C code. 我希望通过mailx向我的C代码中的收件人列表发送一条消息。
I want to send an email containing the contents of the 'message' variable to everyone in the file /home/me/Email_List.txt. 我想向文件/home/me/Email_List.txt中的每个人发送一封包含'message'变量内容的电子邮件。
if(send_email)
{
char* message = "Testing email";
//send contents of 'message' to everyone in /home/me/Email_List.txt
}
I need help with both the C program and the mailx command. 我需要C程序和mailx命令的帮助。 Here's my mailx command that doesn't quite work:
这是我的mailx命令,无法正常工作:
//This works, but I don't want to send the contents of Email_List.txt
cat /home/me/Email_List.txt /home/me/Email_List.txt | mailx -t -s "Test"
//This doesn't work, error:
//cat: cannot open Test Text
cat /home/me/Email_List.txt "Test Text" | mailx -t -s "Test"
I could write my text to a file before sending it, but that seems inefficient. 我可以在发送文本之前将其写入文件,但这似乎效率很低。
Thoughts? 有什么想法吗?
Working at the command line, I got this to work for me (with my normal corporate email address in place of me@example.com
, of course): 在命令行上工作,我得到了这个(我的普通公司电子邮件地址代替了
me@example.com
):
mailx -s "Just a test" -t <<EOF
To: me@example.com
Subject: Just a test with a subject
Just testing mailx -t which seems to ignore -s options too
-=JL=-
EOF
The -s
option subject line was ignored, as hinted in the body text. 如正文中所提示,
-s
选项主题行被忽略。 (This is a mailx
version 12.5 6/20/10
on a machine running a derivative of Ubuntu 12.04 LTS.) (这是运行Ubuntu 12.04 LTS衍生版本的计算机上的
mailx
版本12.5 6/20/10
。)
Note that the To:
line is case-sensitive and space-sensitive (at least there must be a space after the colon). 请注意,
To:
行区分大小写且区分大小写(冒号后面至少必须有一个空格)。 This is standard notation for the headers defined by RFC-822 (or whatever its current incarnation is). 这是RFC-822定义的标头的标准符号(或其当前的形式)。 When I tried with the
-s
option but no Subject:
line, I got a message without a subject in my inbox. 当我尝试使用
-s
选项但没有Subject:
行时,我收到一条消息,收件箱中没有主题。
The following should work for you: 以下应该为您工作:
$ cat /home/me/Email_list.txt
To: My.email@company.com
Subject: Test email
$ { cat /home/me/Email_List.txt; echo "Test Text"; } | mailx -t
$
Note that blank line! 注意空白行! Or you could use a plain
echo;
或者您可以使用简单的
echo;
before the echo "Test text";
在
echo "Test text";
. 。 The semicolons are needed in the
{ ... }
notation. { ... }
表示法中需要分号。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.