0

嘿伙计们,几天来我一直在努力解决这个问题,但我只是在这里失去了它,我正在尝试记录一条消息,这(对我们而言)意味着我们会收到一封典型的响应式电子邮件,您通常会发送到 / from 和其他特殊标题,将其(作为文件附件)包装在另一封电子邮件中,我们将其发送到我们的数据库。

那么我的问题的核心是,我将如何将一封电子邮件(带有标题)包装在另一封电子邮件中?我是否需要先写出初始(内部)电子邮件以归档并通过 MUTT 作为附件添加?我可以在不创建文件的情况下编写附件吗?我有一个我认为它应该如何工作的存根?

#!/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'
4

1 回答 1

1

基本上,您必须构建一个“多部分/混合”电子邮件消息,其中包含一个“消息/rfc822”部分,其中包含您要附上的电子邮件。

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
)

然后您可以构建要发送的消息:

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
)

您现在可以"$msg"使用您选择的任何机制发送:

echo "$msg" | sendmail -oi -t

(这是未经测试的,可能是错误的)

于 2013-10-21T17:33:36.447 回答