linux下c语言读取roed文件,如何使用Linux命令行發送一個文件作為電子郵件附件?...

这篇博客介绍了如何在Unix环境下使用mailx命令发送包含纯文本正文和附件的电子邮件。具体步骤包括使用uuencode编码附件,以及构建包含邮件头部信息的命令行。此外,还提到了使用sendmail发送带有HTML正文和PDF附件的邮件的方法,涉及脚本编写和权限设置。请注意避免频繁使用以防止被标记为垃圾邮件。
摘要由CSDN通过智能技术生成

8

Send a Plaintext body email with one plaintext attachment with mailx:

(

/usr/bin/uuencode attachfile.txt myattachedfilename.txt;

/usr/bin/echo "Body of text"

) | mailx -s 'Subject' youremail@gmail.com

Below is the same command as above, without the newlines

下面是與上面相同的命令,沒有換行。

( /usr/bin/uuencode /home/el/attachfile.txt myattachedfilename.txt; /usr/bin/echo "Body of text" ) | mailx -s 'Subject' youremail@gmail.com

Make sure you have a file /home/el/attachfile.txt defined with this contents:

確保您有一個文件/home/el/attachfile。txt定義的內容如下:

Government discriminates against programmers with cruel/unusual 35 year prison

sentences for making the world's information free, while bankers that pilfer

trillions in citizens assets through systematic inflation get the nod and

walk free among us.

如果您沒有uuencode,請閱讀以下內容:https://unix.stackexchange.com/questions/16277/how-_get - uuencodeto -work。

On Linux, Send HTML body email with a PDF attachment with sendmail:

Make sure you have ksh installed: yum info ksh

確保您已經安裝了ksh: yum info ksh。

Make sure you have sendmail installed and configured.

確保已經安裝並配置了sendmail。

確保您已經安裝了uuencode,並提供了:https://unix.stackexchange.com/questions/16277/how-_get - uuencodeto -work。

Make a new file called test.sh and put it in your home directory: /home/el

新建一個名為test的文件。把它放在你的主目錄:/home/el。

Put the following code in test.sh:

將下列代碼放入test.sh:

#!/usr/bin/ksh

export MAILFROM="el@defiant.com"

export MAILTO="youremail@gmail.com"

export SUBJECT="Test PDF for Email"

export BODY="/home/el/email_body.htm"

export ATTACH="/home/el/pdf-test.pdf"

export MAILPART=`uuidgen` ## Generates Unique ID

export MAILPART_BODY=`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 ""

echo "--$MAILPART"

echo "Content-Type: multipart/alternative; boundary=\"$MAILPART_BODY\""

echo ""

echo "--$MAILPART_BODY"

echo "Content-Type: text/plain; charset=ISO-8859-1"

echo "You need to enable HTML option for email"

echo "--$MAILPART_BODY"

echo "Content-Type: text/html; charset=ISO-8859-1"

echo "Content-Disposition: inline"

cat $BODY

echo "--$MAILPART_BODY--"

echo "--$MAILPART"

echo 'Content-Type: application/pdf; name="'$(basename $ATTACH)'"'

echo "Content-Transfer-Encoding: uuencode"

echo 'Content-Disposition: attachment; filename="'$(basename $ATTACH)'"'

echo ""

uuencode $ATTACH $(basename $ATTACH)

echo "--$MAILPART--"

) | /usr/sbin/sendmail $MAILTO

Change the export variables on the top of test.sh to reflect your address and filenames.

在測試的頂部更改導出變量。sh反映你的地址和文件名。

Download a test pdf document and put it in /home/el called pdf-test.pdf

下載測試pdf文檔並將其放入/home/el中,稱為pdf。

Make a file called /home/el/email_body.htm and put this line in it:

創建一個名為/home/el/email_body的文件。htm,把這條線放進去

this is some bold text

Make sure the pdf file has sufficient 755 permissions.

確保pdf文件有足夠的755權限。

Run the script ./test.sh

運行該腳本。/ test.sh

Check your email inbox, the text should be in HTML format and the pdf file automatically interpreted as a binary file. Take care not to use this function more than say 15 times in a day, even if you send the emails to yourself, spam filters in gmail can blacklist a domain spewing emails without giving you an option to let them through. And you'll find this no longer works, or it only lets through the attachment, or the email doesn't come through at all. If you have to do a lot of testing on this, spread them out over days or you'll be labelled a spammer and this function won't work any more.

檢查你的電子郵件收件箱,文本應該以HTML格式和pdf文件自動解釋為二進制文件。注意不要在一天內使用這個功能超過15次,即使你給自己發郵件,gmail的垃圾郵件過濾器也可以將一個域名列入黑名單,而不給你一個讓他們通過的選項。你會發現它不再有效,或者它只允許通過附件,或者電子郵件根本沒有通過。如果你要做大量的測試,把它們分散幾天,否則你就會被貼上垃圾郵件的標簽,這個功能就不再管用了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值