Bash 将一封MUTT电子邮件包装在另一封MUTT电子邮件中(日志记录)
嘿,伙计们,这几天我一直在想这个问题,但我在这里弄丢了,我在写一封邮件,这(对我们来说)意味着我们会收到一封典型的回复邮件,带有你典型的收件人/发件人和其他特殊的标题,将它(作为文件附件)包装在另一封邮件中,我们会发送给DB 我的问题的核心是,如何将一封电子邮件(带有标题)包装在另一封电子邮件中?我是否需要先将初始(内部)电子邮件写入文件,并通过MUTT将其作为附件添加?我可以在不创建文件的情况下编写附件吗?我有一个我认为应该如何工作的存根Bash 将一封MUTT电子邮件包装在另一封MUTT电子邮件中(日志记录),bash,mutt,journaling,Bash,Mutt,Journaling,嘿,伙计们,这几天我一直在想这个问题,但我在这里弄丢了,我在写一封邮件,这(对我们来说)意味着我们会收到一封典型的回复邮件,带有你典型的收件人/发件人和其他特殊的标题,将它(作为文件附件)包装在另一封邮件中,我们会发送给DB 我的问题的核心是,如何将一封电子邮件(带有标题)包装在另一封电子邮件中?我是否需要先将初始(内部)电子邮件写入文件,并通过MUTT将其作为附件添加?我可以在不创建文件的情况下编写附件吗?我有一个我认为应该如何工作的存根 #!/bin/bash function assemb
#!/bin/bash
function assemble()
{
declare -a argAry=("${!1}")
echo -e "${argAry[@]}" -- $2 |sed "s/^ *//;s/ *$//;s/ \{1,\}/ /g"
}
function generate()
{
hname=`hostname`
tai64=`date| tai64n |cut -c2-25`
uuid4=`python -c 'import uuid; print uuid.uuid4()'`
# return variable as generated string
echo "${hname}-${tai64}-${uuid4}'"
}
function send()
{
attach='' # can't [] && || for some reason
[ '1' == ${ARGS[0]} ] && attach="-e 'my_hdr"
local hdrsTable=(
"${attach} To: ${ARGS[1]}'\n"
"${attach} From: ${ARGS[2]}'\n"
"${attach} X-DOMAIN-SITE-URL: ${ARGS[3]}'\n"
"${attach} X-DOMAIN-MEDIA-TYPE: ${ARGS[4]}\n"
"${attach} X-DOMAIN-DIRECTION: ${ARGS[5]}\n"
"${attach} X-DOMAIN-CAPTURE-DATE: `date`\n"
"${attach} X-DOMAIN-POST-DATE: `date`\n"
"${attach} X-DOMAIN-UTID: `generate`\n"
`[ -a $FILE ] && echo -a $FILE`
)
if [ '0' == $ARGV[0] ]; then
FILE="/tmp/$(basename $0).$$.tmp"
assemble hdrsTable[@] >> "/tmp/${FILE}" # create the temporary file to hold stuff?
else
assemble hdrsTable[@] $1
fi
}
ARGS=("0" "somelivename@domain.com" "someliveemail@domain.com" "www.google.com" "archiver" "out")
send
ARGS=("0" "someforwarder@domain.com" "journaling@ash.domain.com" "www.google.com" "archiver" "out")
send 'root@domain.com'
基本上,您必须构造一个包含“message/rfc822”部分的“multipart/mixed”电子邮件,该部分保存您想要包含的电子邮件
inner_msg=$(cat - <<END_MSG
To: santa.clause@northpole.example.com
From: virginia@doubtful.invalid
Subject: do you exist
I am doubtful
Regards,
V.
END_MSG
)
(这是未经测试的,可能有问题)我看到的其中一个问题是,它并没有真正创建头,只是将它们回显到消息体中。这可能是一个特定于MUTT的东西,尽管我在代码中没有看到“MUTT”。您想在内部电子邮件中添加一些标题,对吗?这是正确的,很抱歉,我标记了问题mutt,但忘了在代码中使用它=/
boundary="this is the boundary: $$-$(date +%s)"
msg=$(cat - << END_MSG
To: recipient@example.com
From: sender@example.com
Subject: I contain a message
Content-Type: multipart/mixed; boundary="$boundary"
Mime-Version: 1.0
This is a multipart message in MIME format.
--$boundary
Content-Type: text/plain; charset=ISO-8859-1
This is the body of the 'container' message.
The email attachment follows.
--$boundary
Content-Type message/rfc822
Content-Disposition: attachment; filename="attached_email.eml"
$inner_msg
--$boundary--
END_MSG
)
echo "$msg" | sendmail -oi -t