cat /dev/urandom
在显示器上创建滚动字符始终是一种有趣的方式,但会生成太多不可打印的字符.
是否有一种简单的方法可以在命令行上对其进行编码,使其所有输出都是可读字符,例如base64或uuencode.
请注意,我更喜欢不需要创建其他文件的解决方案.
目标:使用HTML正文和二进制附件发送邮件(使用sendmail).
遵循以下链接中指定的准则
http://www.unix.com/shell-programming-scripting/159522-sendmail-html-body-attachment-2.html
http://www.unix.com/shell-programming-scripting/58448-sendmail-attachment.html
它的工作范围是HTML主体或带有uuencode的二进制附件,但不是两者兼而有之.
下面给出了sendmail的shell脚本片段.有了这个,HTML正文变得很好,但附件被错误编码/解码,无法查看相同.
请指教.
#!/usr/bin/ksh
export MAILFROM="noreply@site.dom"
export MAILTO="somebody@somesite.com"
export SUBJECT="Test PDF for Email"
export BODY="email_body.htm"
export ATTACH="file.pdf"
export MAILPART=`uuidgen` ## Generates Unique ID
(
echo "From: $MAILFROM"
echo "To: $MAILTO"
echo "Subject: $SUBJECT"
echo "MIME-Version: 1.0"
echo "Content-Type: multipart/mixed; boundary=\"-$MAILPART\""
echo "---$MAILPART"
echo "Content-Type: text/html"
echo "Content-Disposition: inline"
cat $BODY
echo "---$MAILPART"
echo 'Content-Type: application/pdf; name="'$(basename $ATTACH)'"'
echo "Content-Transfer-Encoding: base64"
echo 'Content-Disposition: attachment; filename="'$(basename $ATTACH)'"'
uuencode -m $ATTACH $(basename $ATTACH)
echo "---$MAILPART--"
) | /usr/sbin/sendmail $MAILTO …
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用sendmail发送带附件的邮件.问题是我无法发送主题行.
以下命令行触发两个邮件而不是一个 - 一个带有" Subject : Report
",另一个带有附件:
/usr/bin/gmime-uuencode "/tmp/url_by_ip.txt" "Report.txt" | echo "Subject: Report" | /usr/sbin/sendmail <sender> <receiver>
Run Code Online (Sandbox Code Playgroud) 是否可以使用uuencode
和发送多个附件sendmail
?
在脚本中,我有一个包含需要附加到单个电子邮件的文件的变量,例如:
$attachments=attachment_1.pdf attachment_2.pdf attachment_3.pdf attachment_4.pdf
Run Code Online (Sandbox Code Playgroud)
还有一个$template
变量,如:
$template="Subject: This is the subject
From: no-reply@domain.com
To: %s
Content-Type: text/plain
This is the body.
"
Run Code Online (Sandbox Code Playgroud)
我想出了:
printf "$template" "$recipient" |
sendmail -oi -t
Run Code Online (Sandbox Code Playgroud)
在此范围内的某个地方,我必须附加$attachments
变量中的所有内容?
我是一个新手用户试图弄清楚如何使用uuencode方法.我们有一个表单,只允许上传一个文本文件.现在看起来只会上传zip文件.我试图包含uuencode方法将字节转换为String,这样我们就不必修改其余的代码来容纳二进制文件.
原始代码:
public void SettingUpload(File inputfile) {
this.inputfile = inputfile;
}
Run Code Online (Sandbox Code Playgroud)
我改成了
public void SettingUpload(File inputfile){
UUEncoder uuec = new UUEncoder();
try{
InputStream is = new FileInputStream(inputfile);
OutputStream os = new FileOutputStream(inputfile);
uuec.encodeBuffer(is, os);
this.inputfile = inputfile;
}catch (Throwable error) {
reportError(error, "Error converting zipfile");
}
}
Run Code Online (Sandbox Code Playgroud)
当我测试它时,我得到了一个java.io.EOFException.我抓住了uuencoded文件并手动uudecoded它.当我试图解压缩时,
bash1:~>unzip s6b0c9e663c74f72941bd8271a5fac3b.bin
Archive: s6b0c9e663c74f72941bd8271a5fac3b.bin
End-of-central-directory signature not found. Either this file is not
a zipfile, or it constitutes one disk of a multi-part archive. In the
Run Code Online (Sandbox Code Playgroud)
编辑:
我改成了:
public void SettingUpload(File inputfile){ …
Run Code Online (Sandbox Code Playgroud) 我有一个数据流试图用UUencode编码,以便将数据传递到外部芯片.该芯片一次接受512字节的原始数据.我用UUencode编码512字节.
据我所知,数据应转换为11行45个字节(编码后为60个字节)和1个剩余的17个字节行.
显然,17个字节不能直接映射到uuencoded段,因为它不是3的倍数,但是当我得到uuencoded数据时,最后一行返回24个编码字节(或18个原始字节).
这意味着我现在总共有513个字节的数据.我的问题是,这是我的uuencode算法的错误(虽然从纯粹的数学角度来看,我看不出它是怎么回事)或者,额外的字节来自何处,以及如何再次摆脱它?