[使用带有uuencode的cat通过unix发送电子邮件

问题描述 投票:0回答:1

[这里我正在使用sun Solaris 10,我曾尝试发送带和不带附件的普通电子邮件,并且对我来说效果很好,但现在我正尝试收集文件元素并在相同的位置发送附件电子邮件,但不起作用

这是我的result.txt文件正文:

Total Number of Files = 8
Total Number of Fixed Files = 4
Total Number of Notification Files = 4

Total Number of Courrpted Files = 0

Total Execution Time = 3 Seconds.

这是我的data.txt文件正文:

Notification Files : 
file number 1
file number 2

unix命令:

RECEIPIENTS="[email protected]"
SUBJECT="!! testtt !!"
(cat Results.txt ; uuencode Data.txt Data.txt) | mailx -s "$SUBJECT" -c [email protected],[email protected] -r [email protected] $RECEIPIENTS

这是我发送电子邮件后得到的:

Total Number of Files = 8
Total Number of Fixed Files = 4
Total Number of Notification Files = 4

Total Number of Courrpted Files = 0

Total Execution Time = 3 Seconds.
begin 777 Data
M#0I.;W1I9FEC871I;VX@1FEL97,@.B -"@T*,2U#1$M(34LU2D]21DPP,#0R
M,@T*,BU#1$Q454]-2D]21DPP-S$Q- T*,RU#1$Q454]-2D]21DPP-S$Q-@T* M-"U#1$Q604Q-2D]21DPP-#0U, T*#0I&:7AE9"!&:6QE<R Z( T*#0HQ+4-$ M051'2SE*3U)&3# P,3$T#0HR+4-$051'2SE*3U)&3# P,3$U#0HS+4-$0TA.
C0U5*3U)&3#,Q.3DT#0HT+4-$0TA.0U5*3U)&3#,Q.3DU#0HU

end

注意:如果我使用echoecho -e或使用uuencode附加文件而不使用cat可以正常工作,则仅当我将catuuencode一起使用时才出现此问题

email solaris encode solaris-10
1个回答
1
投票

在上一个千年中有一段时间uuencode是有意义的,但是在这个时代,您确实应该使用MIME。

[这是一个简单的Python 3脚本,它将来自标准输入和附件的消息组合成有效的RFC822消息,您可以使用sendmail或类似形式发送该消息。它是基于Python documentation's examples.

#!/usr/bin/env python3

from email.message import EmailMessage
import sys

msg = EmailMessage()
msg['From'] = sys.argv[1]
msg['To'] = sys.argv[2]
msg['Subject'] = sys.argv[3]
# Don't mess with the preamble, the documentation is wrong to suggest you do

msg.set_content(''.join([line for line in sys.stdin]))

with open(sys.argv[4], 'r') as attachment:
    msg.add_attachment(attachment.read(), maintype='text', subtype='plain')

print(msg.as_string())

要在您的示例中使用它,

# If `sendmail` is not in your `PATH`, maybe add it.
# For example, if you have it in `/usr/lib/sendmail`
# and `/usr/lib´ is not in your `PATH`, you can add it with
#PATH=$PATH:/usr/lib

# Don't use upper case for private variables; check spelling of "recipients"
# To demo an example of sending to multiple addresses, adds a second recipient
recipients="[email protected],[email protected]"
subject="!! testtt !!"

python3 path/to/script.py "[email protected]" "$recipients" "$subject" Data.txt <Results.txt |
sendmail -oi -t

您可以省略到sendmail的管道,以查看消息的外观。它创建了一个多部分的MIME消息,而不是消息正文中的uuencode smack dab,它分为两部分,其中一部分是内联的,包含来自标准输入的文本,而另一部分则被正确地标记为附件。它有点笨重,但我在此处包括一个示例只是为了向您展示。

From: [email protected]
To: [email protected],[email protected]
Subject: !! testtt !!
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="===============2189027902917283968=="

--===============2189027902917283968==
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit

Total Number of Files = 8
Total Number of Fixed Files = 4
Total Number of Notification Files = 4

Total Number of Courrpted Files = 0

Total Execution Time = 3 Seconds.

--===============2189027902917283968==
Content-Type: text/plain
Content-Transfer-Encoding: base64
MIME-Version: 1.0
Content-Disposition: attachment

Tm90aWZpY2F0aW9uIEZpbGVzIDogCmZpbGUgbnVtYmVyIDEKZmlsZSBudW1iZXIgMgo=

--===============2189027902917283968==--

此附件在此特定示例中非常不必要地base64编码;如果您绝对需要人类可读的Python代码,则可以对其进行调整(但是uuencode都不是)。

(而且,不知道为什么主体部分具有单独的MIME-Version:标头-似乎是个错误。]

© www.soinside.com 2019 - 2024. All rights reserved.