Skip to content Skip सामग्री के लिए


How to send email from the Linux command line कैसे Linux कमांड लाइन से ईमेल भेजने के लिए

ईमेललिनक्स

The Linux command line can be very powerful once you know how to use it. लिनक्स आदेश पंक्ति बहुत शक्तिशाली एक बार तुम्हें पता है कि यह कैसे उपयोग हो सकता है. You can parse data, monitor processes, and do a lot of other useful and cool things using it. आप डेटा की निगरानी प्रक्रियाओं को पार्स सकते हैं, और अन्य उपयोगी और ठंडी चीजों का एक बहुत कुछ कर इसे इस्तेमाल करते हैं. There often comes a need to generate a report and mail it out. वहां अक्सर एक ऐसी रिपोर्ट को पैदा करते हैं और यह मेल बाहर की जरूरत है. It could be as simple a requirement as a notification that the day's backup went through fine, or did not. यह एक सूचना है कि दिन के ठीक बैकअप के माध्यम से चला गया, या के रूप में सरल एक आवश्यकता के रूप में हो सकता है नहीं था. I'll help you get started with sending mails from the Linux command line and in shell scripts. मैं मदद करूँगा तुम Linux कमांड लाइन से मेल भेजने और खोल लिपियों के साथ आरंभ करने के लिए. We will also cover sending attachments from the command line. हम भी कमांड लाइन से अनुलग्नकों को भेजने को कवर किया जाएगा. We will begin with the “mail” command. हम "मेल" कमांड के साथ शुरू हो जाएगा.

MAIL मेल

First run a quick test to make sure the “sendmail” application is installed and working correctly. पहले एक त्वरित परीक्षण को यकीन है कि sendmail "आवेदन" और सही ढंग से काम कर रहा है स्थापित कर चलाते हैं. Execute the following command, replacing “you@youremailid.com” with your e-mail address. निम्नलिखित कमांड चलाएँ, आपके ई मेल पते के साथ "you@youremailid.com" की जगह ले.

# mail -s “Hello world” you@youremailid.com # मेल-s "दुनिया नमस्ते you@youremailid.com"

Hit the return key and you will come to a new line. वापस कुंजी मारो और तुम एक नई लाइन के लिए आ जाएगा. Enter the text “This is a test from my server”. पाठ दर्ज करें "यह मेरा सर्वर से एक परीक्षण है." Follow up the text by hitting the return key again. वापस कुंजी फिर मार से ऊपर का पालन करें पाठ. Then hit the key combination of Control+D to continue. तब नियंत्रण कुंजी संयोजन हिट + D जारी रखने के लिए. The command prompt will ask you if you want to mark a copy of the mail to any other address, hit Control+D again. आदेश तत्काल आपसे पूछेंगे कि क्या आप किसी अन्य पते पर मेल की एक प्रतिलिपि चिह्न चाहते हैं, करेंगे नियंत्रण + फिर डी मारा. Check your mailbox. आपके मेलबॉक्स की जाँच करें. This command will send out a mail to the email id mentioned with the subject, “Hello world”. इस आदेश से ईमेल भेज एक मेल होगी विषय के साथ उल्लेख किया आईडी, "दुनिया हैलो".

To add content to the body of the mail while running the command you can use the following options. इस मेल के शरीर के लिए सामग्री जोड़ने जबकि कमान आप निम्नलिखित विकल्पों का उपयोग कर सकते हैं रहा है. If you want to add text on your own: यदि आप अपने खुद पाठ जोड़ना चाहते हैं:

# echo “This will go into the body of the mail.” | mail -s “Hello world” you@youremailid.com # गूंज "यह मेल के शरीर में जाना होगा." | मेल-s "दुनिया नमस्ते you@youremailid.com"

And if you want mail to read the content from a file: और अगर आप मेल एक फ़ाइल से सामग्री को पढ़ने के लिए करना चाहते हैं:

# mail -s “Hello world” you@youremailid.com < /home/calvin/application.log # मेल-s "दुनिया नमस्ते you@youremailid.com" </ घर / केल्विन / application.log

Some other useful options in the mail command are: कुछ अन्य मेल कमान में उपयोगी विकल्प हैं:

-s subject (The subject of the mail) -s विषय मेल का (विषय)
-c email-address (Mark a copy to this “email-address”, or CC) ईमेल-c-मार्क (यह "ईमेल का पता", या प्रतिलिपि को संबोधित एक प्रतिलिपि)
-b email-address (Mark a blind carbon copy to this “email-address”, or BCC) ईमेल-B-मार्क (यह "ईमेल का पता", या बीसीसी के पते में एक अंधा कार्बन कॉपी)

Here's how you might use these options: यहाँ आप इन विकल्पों का उपयोग कैसे सकता है:

# echo “Welcome to the world of Calvin n Hobbes” | mail -s “Hello world” calvin@cnh.com -c hobbes@cnh.com -b susie.derkins@cnh.com # प्रतिध्वनि 'में आपका स्वागत है केल्विन n होब्स की दुनिया को' | मेल-s "दुनिया नमस्ते calvin@cnh.com 'hobbes@cnh.com ग cnh.com @ susie.derkins ख

MUTT मठ

One of major drawbacks of using the mail command is that it does not support the sending of attachments. मेल आदेश का उपयोग कर के प्रमुख कमियां में से एक यह है कि यह समर्थन नहीं करता अनुलग्नकों को भेजने की. mutt, on the other hand, does support it. मठ, दूसरे हाथ पर, यह समर्थन करता है. I've found this feature particularly useful for scripts that generate non-textual reports or backups which are relatively small in size which I'd like to backup elsewhere. मैं इस स्क्रिप्ट है कि गैर शाब्दिक रिपोर्ट या बैकअप जो आकार में अपेक्षाकृत छोटे हैं जो मैं कहीं और बैकअप के लिए करना चाहते हैं उत्पन्न करने के लिए विशेष रूप से उपयोगी सुविधा मिल गया है. 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 # गूंज "एक लगाव भेजा जा रहा है." | मठ के एक backup.zip-लगाव s "" 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. इस कमान एक मेल के विषय के साथ calvin@cnh.com भेजेंगे (-s) "संलग्नक", शरीर पाठ "एक लगाव भेजा जा रहा है.", लगाव युक्त (-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 ! # / bin / मार
df -h | mail -s “disk space report” calvin@cnh.com df-h | मेल calvin@cnh.com s "डिस्क स्थान की रिपोर्ट"

Save these lines in a file on your Linux server and run it. आपके Linux सर्वर पर एक फ़ाइल में इन लाइनों को सहेजें और चलाते हैं. 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 ! # / bin / मार
df -h > /tmp/mail_report.log df-h> / tmp / mail_report.log
free -m >> /tmp/mail_report.log मुक्त मी>> / tmp / mail_report.log
mail -s “disk and RAM report” calvin@cnh.com < /tmp/mail_report.log मेल डिस्क s "और राम की रिपोर्ट" calvin@cnh.com </ tmp / mail_report.log

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 ! # / bin / मार
tar -zcf /tmp/backup.tar.gz /home/calvin/files निशाना zcf / tmp / backup.tar.gz / घर केल्विन / / फ़ाइलें
echo | mutt -a /tmp/backup.tar.gz -s “daily backup of data” calvin@cnh.com प्रतिध्वनि | मठ के एक tmp / backup.tar.gz /-s "डेटा के दैनिक बैकअप" 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. यह मिलना चाहिए आपको मेल भेजने से शुरू Linux कमांड लाइन और खोल लिपियों के रूप में. Read up the “man page” for both mail and mutt for more options. पढ़ें "दोनों मेल और अधिक विकल्पों के लिए और मठ के लिए आदमी पृष्ठ" चुप.

Posted in पोस्ट में Email ईमेल , , Guest Blogger अतिथि ब्लॉगर , , Linux लिनक्स . .

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. तुम हमेशा इस ईमेल सदस्यता से बाहर किसी भी समय विकल्प चुन सकते हैं.

12 Responses 12 उत्तर

Stay in touch with the conversation, subscribe to the बातचीत के साथ संपर्क में रहो, की सदस्यता लें RSS feed for comments on this post आरएसएस के इस पोस्ट पर टिप्पणियों के लिए फ़ीड . .

  1. Michal मीकल says कहते हैं,

    You may want to have a look at आप एक नज़र में हो सकते हैं smtp-client.pl SMTP-client.pl . . Check out the usage examples. बाहर उपयोग के उदाहरण देखें. I'd say it's the ultimate command line smtp client, but I'ma little biased मैं यह अंतिम आदेश पंक्ति SMTP ग्राहक कहना है, लेकिन था I'ma थोड़ा पक्षपाती ;-)

  2. Matt says मैट कहते हैं,

    echo | mutt -a -s /tmp/backup.tar.gz “daily backup of data” प्रतिध्वनि | मठ के एक-s / tmp / डाटा के दैनिक बैकअप backup.tar.gz "" calvin@cnh.com calvin@cnh.com

    should be: जाना चाहिए:

    echo | mutt -a /tmp/backup.tar.gz -s “daily backup of data” प्रतिध्वनि | मठ के एक tmp / backup.tar.gz /-s "डेटा के दैनिक बैकअप" calvin@cnh.com calvin@cnh.com

  3. Ross McKillop रॉस McKillop says कहते हैं,

    Matt - मैट --

    Thanks very much for catching that! बहुत पकड़ने के लिए धन्यवाद कि! I've made the correction. मैं सुधार कर लिया है. Cheers! चीयर्स!

  4. Jens Arnfelt says Jens Arnfelt कहते हैं,

    Hi नमस्ते

    You can actually send binary attachment via “mail” the following way : आप वास्तव में "मेल" निम्नलिखित तरीके से होकर द्विआधारी अनुलग्नक भेज सकते हैं:

    uuencode /etc/hosts /etc/hosts | mail -s “mail with binary attachment” uuencode / etc / मेजबान / etc / मेजबान | मेल-s द्विआधारी अनुलग्नक के साथ मेल "" me@mydomain.org me@mydomain.org

    BR बी.आर.
    Jens Arnfelt Jens Arnfelt

  5. joviano says joviano कहते हैं,

    Basically have a test script, whose output comes by mail to me with the use of the command taken from this article: मूल रूप से एक परीक्षण लिपि, जिनकी उत्पादन किया है इस लेख से ले कमांड के प्रयोग के साथ मुझे डाक से आता है:

    echo `my test script` | mail -s “Test Result” प्रतिध्वनि `अपने परीक्षण लिपि '| मेल-s" टेस्ट के परिणाम " my_mail@mail.com my_mail@mail.com

    the problem here is that when i do this.. यहाँ समस्या यह है कि जब मैं इस है .. it works correctly on the mailing front, however the mail that i then get ignores the line breaks in the output of the scripts. यह मेलिंग के मोर्चे पर सही ढंग से काम करती है, फिर भी मेल है कि मैं तो मिल लाइन की अनदेखी लिपियों के उत्पादन में टूट जाता है. I really need the line breaks for readability of the output results.. मैं वास्तव में रेखा की जरूरत उत्पादन परिणामों की पठनीयता के लिए टूट जाता है ..

    any pointers on how i could achieve this ?? मैं कैसे इस लक्ष्य को हासिल सकता है पर कोई संकेत? .. .. would really like some help here वास्तव में कुछ मदद करना चाहेंगे यहाँ

  6. martin says मार्टिन कहते हैं,

    I'm looking for a program that will run from a script and will send mail via gmail smtp server. मैं एक प्रोग्राम है कि एक स्क्रिप्ट से चलाने और जीमेल SMTP सर्वर के माध्यम से मेल भेज करेंगे के लिए देख रहा हूँ. Any ideas? किसी भी विचार?

  7. Michal मीकल says कहते हैं,

    martin: have a look at मार्टिन: एक नज़र में है smtp-client.pl SMTP-client.pl – it is designed to run from a script or a cron job and send email through a specified server. - यह एक निर्दिष्ट सर्वर के माध्यम से एक लिपि या एक क्रॉन जॉब और ईमेल भेजने से चलाने के लिए बनाया गया है. For example: उदाहरण के लिए:

    smtp-client.pl --server smtp.gmail.com --from someone@gmail.com --to some@body.else --subject Blah --attach /path/to/a/picture.png smtp-client.pl --server smtp.gmail.com --from someone@gmail.com --to some@body.else --subject Blah --attach /path/to/a/picture.png smtp-client.pl --server smtp.gmail.com --from someone@gmail.com --to some@body.else --subject Blah --attach /path/to/a/picture.png smtp-client.pl --server smtp.gmail.com --from someone@gmail.com --to some@body.else --subject Blah --attach /path/to/a/picture.png smtp-client.pl --server smtp.gmail.com --from someone@gmail.com --to some@body.else --subject Blah --attach /path/to/a/picture.png

    It can also authenticate with a Gmail username and password among other things. यह भी एक Gmail उपयोगकर्ता नाम अन्य बातों के अलावा और पासवर्ड से प्रमाणित कर सकते हैं.

  8. martin says मार्टिन कहते हैं,

    Thanks Michal. धन्यवाद मीकल. I'll check that out. मैं उस से बाहर देखता हूँ.

  9. Sujith John says Sujith जॉन कहते हैं,

    An excellent tutorial !! एक उत्कृष्ट ट्यूटोरियल! Thanks Much बहुत धन्यवाद

  10. Vasanth says वसंत कहते हैं,

    Thank You. धन्यवाद. i exactly needed this. मैं वास्तव में इस की जरूरत है.

    Thank you धन्यवाद :-)

  11. John Britto.J says जॉन कहते हैं, Britto.J

    Friends I tried the procedure what is given for sending mail through command line. दोस्तों मैं प्रक्रिया क्या कमांड लाइन के माध्यम से मेल भेजने के लिए दिया जाता है की कोशिश की.
    I was able to type subject , the message and even cc. मैं प्रकार के विषय, संदेश और भी सीसी करने में सक्षम था. But when I checked in my account there was no mail received like this. लेकिन मैं वहाँ मेरे खाते में जब जाँच की कोई मेल था इस तरह से प्राप्त की.

Continuing the Discussion चर्चा सतत

  1. How to quickly add Contacts to your Address Book from Mail | TuxWire : The Linux Blog कैसे जल्दी से मेल से अपनी पता पुस्तिका में जोड़ने के लिए संपर्क | TuxWire: लिनक्स ब्लॉग linked to this post on September 22, 2009 22 सितम्बर 2009 को इस पोस्ट के लिए लिंक

    [...] How to send email from the Linux command line [...] [...] कैसे Linux कमांड लाइन से ईमेल भेजने के लिए [...]



Some HTML is OK कुछ HTML है ठीक है

or, reply to this post via या, इस पोस्ट के माध्यम से जवाब trackback Trackback . .