【问题标题】:Send attached file with mailx使用 mailx 发送附件
【发布时间】:2021-08-16 04:07:30
【问题描述】:

我正在尝试以这种方式从 shell 脚本发送带有 uuencode 的附件:

uuencode logq.txt logq.txt |mail -s "DB Capacity" xxxx@000.net

我收到了加密的文件,甚至没有附加..

例如 -

begin 664 logq.txt
M"E1U92!-87(@,CD@(" @(" @(" @(" @(" @(" @(" @(" @(" @(" @(" @ M(" @(" @(" @(" @(" @(" @(" @(" @(" @<&%G92 @(" Q"B @(" @(" @ M(" @(" @(" @(" @(" @(" @(" @(" @4$U-($1"($-!4$%

有人可以告诉我如何解决它吗?

【问题讨论】:

标签: unix


【解决方案1】:

请参阅我对此问题的回答:How to send HTML body email with multiple text attachments using sendmail,了解如何在 Unix bash 脚本中发送附件。

编辑

根据您的最新要求,这里有一个用于发送纯文本附件的简单 Unix 脚本:

FROM=from-email@example.com
TO=to-email@example.com
SUBJECT="PMM DB CAPACITY"
BODY="Hi, This email comes with a text attachment. Thanks!"
TXTFILE="/tti/netrac/integration/scripts/maint_scripts/log.txt log.txt"    
BOUNDARY="=== This is the boundary between parts of the message. ==="
{
   echo  "From: ${FROM}"
   echo  "To: ${TO}"
   echo  "Subject: ${SUBJECT}"
   echo  "MIME-Version: 1.0"
   echo  "Content-Type: MULTIPART/MIXED; "
   echo  "    BOUNDARY="\"${BOUNDARY}\"
   echo
   echo  "        This message is in MIME format.  But if you can see this,"
   echo  "        you aren't using a MIME aware mail program.  You shouldn't "
   echo  "        have too many problems because this message is entirely in"
   echo  "        ASCII and is designed to be readable with old mail software."
   echo
   echo  "--${BOUNDARY}"
   echo  "Content-Type: TEXT/PLAIN; charset=US-ASCII"
   echo
   echo  "${BODY}"
   echo
   echo
   echo  "--${BOUNDARY}"
   echo  "Content-Type: TEXT/PLAIN; charset=US-ASCII; name="${TXTFILE}
   echo  "Content-Disposition: attachment; filename="`$(basename ${TXTFILE})
   echo
   cat ${TXTFILE}
   echo
   echo  "--${BOUNDARY}--"
} | sendmail -t

只要确保你的 bash 路径中有 sendmail。

发送附件的替代命令

(echo "Hi, this mail has an attachment."; uuencode attachment.txt attachment.txt) | mail -s "Some Subject" to-email@example.com 

【讨论】:

  • 我在哪里添加文件?到 $ZIP?是 var 持有 var 吗?
  • 是的,该示例附加了 2 个文件。 1:Shell var $ZIPFILE 应该指向内容类型为 application/zip 的 zip 和 2:$PDFFILE 应该指向内容类型为 application/pdf 的 pdf 所以根据您的需要,请随时更改变量名称及其内容类型。
  • 嗨,首先我会感谢你的。
  • .... 第二 - 我的问题是我收到了编码的 txt 文件,但没有在我的 Outlook 中解码它的选项。谢谢
  • @user644535:我也使用 Outlook,并且能够在 Outlook 中正常接收所有这些附件。我可以知道您要发送什么类型的附件,例如:文本、csv、doc、pdf 等,然后我可以根据您的需要自定义该代码并更新我的答案。
猜你喜欢
  • 2014-08-09
  • 2023-03-19
  • 2020-06-02
  • 1970-01-01
  • 2010-09-10
  • 2014-10-29
  • 1970-01-01
  • 2016-08-16
  • 1970-01-01
相关资源
最近更新 更多