linux桌面如何发邮件,如何在linux终端发电子邮件(带附件)

How To Send an Email With Attachment and Body from Linuxnn

by Ramesh Natarajan on December 30, 2009

Question: How do I send an email with attachment from Linux command-line

(or shell script)? Also, can I send both attachment and body text together

in an email from Linux command-line?

Answer: You can send both attachment and body text (or just the attachment

with a subject line) from Linux command line as explained below.

1. Send an Email with Subject and Body

Typically you would send an email from the Linux command line with a

subject line and body text as shown below. Please note that you should

type a . (period) in a separate line to indicate the body of the text is

over.

$ mail ramesh.thegeekstuff@gmail.com

Subject: Email Testing from Linux

Dear,

It is very easy to send an email from Linux command line.

If you want to read the body text from a file (for example,

body-message.txt), send the email as shown below.

$ cat body-message.txt | mail -s "Email testing from Linux"

ramesh@thegeekstuff.com

2. Send an Email with Attachment

To send an attachment from the email, use uuencode command. On RedHat (and

related distributions), uuencode is part of the sharutils package. So,

install the sharutils as shown below.

# rpm -ivh sharutils-4.6.1-2.i386.rpm

Preparing... ############################## [100%]

1:sharutils ############################## [100%]

Once you've confirmed that you have uuencode, send the email with an

attachment as shown below.

$ uuencode input-attachment.txt output-attachment.txt | \

mail -s "Email With Attachment" ramesh.thegeekstuff@gmail.com

In this example,

input-attachment.txt is the file that you like to attach to the email.

If you like the file to be attached with a different name, specify it as

2nd parameter to the uuencode. In this example, the intput-attachment.txt

file content will be attached as output-attachment.txt

Note: uuencode can also be used to send base64 attachments as shown below.

$ uuencode -m input-attachment.txt output-attachment.txt | \

mail -s "Email With Base64 Attachment" ramesh.thegeekstuff@gmail.com

3. Send an Email with Attachment and Body

You can send an email with both attachment and body message as shown below.

$ ( cat body-message.txt; uuencode input-attachment.txt

output-attachment.txt ) \

| mail -s "Email With Body Text and Attachment"

ramesh.thegeekstuff@gmail.com

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值