كيف أن يرسل بريد إلكترونيّ من [لينوإكس] [كمّند لين]

ب [سوكريت] [دهندهنيا] على ديسمبر - كانون الأوّل 1, 2008

بريد إلكترونيّ [لينوإكس]

[لينوإكس] [كمّند لين] يستطيع كنت جدّا قوّيّة ما إن أنت تعرف كيف أن يستعمل هو. أنت يستطيع أعربت معطيات, مدربة عمليات, ويتمّ [ا لوت] من أخرى مفيدة وأشياء باردة يستعمل هو. يأتي هناك غالبا حاجة أن يلد تقرير وأرسلت هو خارجا. هو استطاع كنت بسيطة متطلب مثل بما أنّ إشعار أنّ اليوم ذهب نسخة احتياطيّة من خلال غرامة, أو أتمّ لم. أنا سأساعد أنت حصلت يبدأ مع يرسل بريد إلكترونيّ من [لينوإكس] [كمّند لين] وفي [شلّ سكريبت]. نحن أيضا سنغطّي يرسل ملاحق من ال [كمّند لين]. نحن سنبدأ مع ال "بريد إلكترونيّ" أمر.

بريد إلكترونيّ

شوط أولى إختبار سريعة أن يتأكّد ال "[سندميل]" تطبيق يركّب ويعمل بشكل صحيح. نفّذت الأمر تالي, يستبدل "[يوووورميليد.كم]" مع ك بريد إلكترونيّ عنوان.

# بريد إلكترونيّ - [س] "مرحبا عالم" [يوووورميليد.كم]

ضربت ال [رتثرن كي] وسيأتي أنت إلى [نو لين]. دخلت النص "هذا يكون إختبار من نادلتي". متابعة النص ب يضرب ال [رتثرن كي] ثانية. بعد ذلك ضربت ال [كي كمبينأيشن] من [كنترولد] أن يستمرّ. الأمر سيسأل رسالة حثّ أنت إن أنت تريد أن يعلم نسخة من البريد إلكترونيّ إلى أيّ أخرى عنوان, إصابة [كنترولد] ثانية. فحصت صندوق بريدك. سيبعث هذا أمر بريد إلكترونيّ إلى البريد إلكترونيّ [إيد] يذكر مع الموضوع, "مرحبا عالم".

أن يضيف محتوى إلى الجسم من البريد إلكترونيّ بينما يركض الأمر أنت يستطيع استعملت الخيارات تالي. إن أنت تريد أن يضيف نص على ك خاصّة:

# دوّيت "هذا سيذهب داخل الجسم من البريد إلكترونيّ." | بريد إلكترونيّ - [س] "مرحبا عالم" [يوووورميليد.كم]

وإن أنت تريد بريد إلكترونيّ أن يقرأ المحتوى من مبرد:

# بريد إلكترونيّ - [س] "مرحبا عالم" [يوووورميليد.كم]

بعض أخرى خيارات مفيدة في البريد إلكترونيّ أمر:

- [س] موضوع (الموضوع من البريد إلكترونيّ)
- [ك] [إميل-دّرسّ] (علمت نسخة إلى هذا "[إميل-دّرسّ]", أو [كّ])
- [ب] [إميل-دّرسّ] (علمت [كربون كبي] عمياء إلى هذا "[إميل-دّرسّ]", أو [بكّ])

هنا كيف أنت أمكن استعملت هذا خيارات:

# دوّيت "ترحيب إلى العالم [كلفين] ن [هوبّس]" | بريد إلكترونيّ - [س] "مرحبا عالم" [كلفينكنه.كم] - [ك] [هوبّسكنه.كم] - [ب] [سوس.دركينسكنه.كم]

[موتّ]

واحدة من عيب انسحاب كبريات من يستعمل البريد إلكترونيّ أمر أنّ لا يساند هو ال يرسل من ملاحق. يساند [موتّ], [أن ث ون هند], هو. أنا قد أسّست هذا سمة بشكل خاصّ مفيدة لنصوص أنّ يلد [نون-تإكستثل] تقارير أو نسخة احتياطيّة أيّ يكون نسبيّا صغيرة في حجم أيّ أنا أحبّت إلى نسخة احتياطيّة في مكان آخر. Of course, mutt allows you to do a lot more than just send attachments. It is a much more complete command line mail client than the “mail” command. Right now we’ll just explore the basic stuff we might need often. Here’s how you would attach a file to a mail:

# echo “Sending an attachment.” | mutt -a backup.zip -s “attachment” calvin@cnh.com

This command will send a mail to calvin@cnh.com with the subject (-s) “attachment”, the body text “Sending an attachment.”, containing the attachment (-a) backup.zip. Like with the mail command you can use the “-c” option to mark a copy to another mail id.

SENDING MAIL FROM A SHELL SCRIPT

Now, with the basics covered you can send mails from your shell scripts. Here’s a simple shell script that gives you a reading of the usage of space on your partitions and mails the data to you.

#!/bin/bash
df -h | mail -s “disk space report” calvin@cnh.com

Save these lines in a file on your Linux server and run it. You should receive a mail containing the results of the command. If, however, you need to send more data than just this you will need to write the data to a text file and enter it into the mail body while composing the mail. Here’s and example of a shell script that gets the disk usage as well as the memory usage, writes the data into a temporary file, and then enters it all into the body of the mail being sent out:

#!/bin/bash
df -h > /tmp/mail_report.log
free -m >> /tmp/mail_report.log
mail -s “disk and RAM report” calvin@cnh.com

Now here’s a more complicated problem. You have to take a backup of a few files and mail then out. First the directory to be mailed out is archived. Then it is sent as an email attachment using mutt. Here’s a script to do just that:

#!/bin/bash
tar -zcf /tmp/backup.tar.gz /home/calvin/files
echo | mutt -a /tmp/backup.tar.gz -s “daily backup of data” calvin@cnh.com

The echo at the start of the last line adds a blank into the body of the mail being set out.

This should get you started with sending mails form the Linux command line and from shell scripts. Read up the “man page” for both mail and mutt for more options.

If this post helped you, I would be extremely grateful if you could take 3 minutes (I timed it) to complete this survey. If you enter your email address at the end of the survey, you'll be entered into a contest to win a $25 USD Amazon Gift Certificate. You do not need to enter your name or email address (though you won't be entered into the contest) to complete the survey. No personally identifiable information is gathered. If you do opt to enter the contest, your email address will not be sold or used for any kind of communication, other than to notify you if you won the contest. After the contest ends all email addresses will be deleted. Thanks very much in advance!!
Related Posts:
  • How to set up Evolution for email
  • Some useful Linux bash tricks
  • How to monitor your Linux machine with netstat
  • How to set the date on your Linux machine
  • Linux command line magic - find and replace
  • Get Simple Help tutorials just like this one in your email inbox every day - for free! Just enter your email address below:

    You can always opt out of this email subscription at any time.

    { 3 comments… read them below or add one }

    1 Michal 12.08.08 at 3:20 am

    You may want to have a look at smtp-client.pl. Check out the usage examples. I’d say it’s the ultimate command line smtp client, but I’m a little biased ;-)

    2 Matt 01.21.09 at 11:24 pm

    echo | mutt -a -s /tmp/backup.tar.gz ?daily backup of data? calvin@cnh.com

    should be:

    echo | mutt -a /tmp/backup.tar.gz -s ?daily backup of data? calvin@cnh.com

    3 Ross McKillop 01.22.09 at 12:47 am

    Matt -

    Thanks very much for catching that! I’ve made the correction. Cheers!

    Leave a Comment

    You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>