One of the mutual chore for programmers working inwards Linux machine is to shipping emails, for example, your Java applications are running on Linux similar RHEL v or RHEL vi version together with you lot quest to shipping a written report of all the clients connecting to your application. An slow means to achieve this is to write a shell script, which volition dump all clients inwards the log file together with so operate grep command together with generate a report. If you lot have got to grep logs from multiple hosts, you lot tin too operate the SSH ascendency to run the same ascendency on multiple hosts. Once you lot have got got the listing of clients connecting to your application, you lot tin exactly shipping the CSV file to yourself inwards an electronic mail or to your application DL, or a grouping of users you lot desire to.
Now, the query is how to shipping an electronic mail from Linux? together with to a greater extent than importantly how to shipping an electronic mail alongside attachments? Well, in that location are unlike options based on whether you lot are running on RHEL v or RHEL 6.
For example, my favorite means to shipping an electronic mail alongside attachment was yesteryear using the uuencode together with mail ascendency but, unfortunately, that didn't piece of work when nosotros migrated to RHEL 6. So, I had to operate the mailx command alongside -a flag for attachments.
But, mailx is non the alone means to shipping electronic mail from Linux, you lot tin too operate the mutt ascendency if its available to you.
In this article, I'll demo you how to shipping an electronic mail alongside trunk together with attachment using mailx together with mutt ascendency from a Linux host.
There may live on a duo of to a greater extent than options but I haven't explored much, for me these ii industrial plant fine inwards both RHEL v together with RHEL vi hosts together with I was able to complete my scripts alongside these ii commands. I'll explore to a greater extent than when I acquire roughly fourth dimension but if you lot have got roughly thoughts experience gratis to percentage alongside us together with if you lot desire to larn more, I propose you lot acquire through Linux Administration Bootcamp course on Udemy.
Syntax of mailx ascendency :
mailx -eiIUdEFntBDNHRV -T FILE -u USER -h hops -r address -s SUBJECT -a FILE -q FILE -f FILE -A ACCOUNT -b USERS -c USERS -S OPTION users
You tin run into that -s is used for a plain of study together with -a is used for attachment. You tin too CC users using -c options together with BCC users using -b option.
Now, 1 question, which may come upward to your heed is what would live on the sender's electronic mail address when you lot shipping post service from Linux? Well, it depends on the user who is sending an email.
For example, if you lot log inwards using your personal operate together with shipping post service so it would live on your electronic mail but if you lot log inwards every bit application user together with shipping an electronic mail so it would live on the electronic mail configured for that application user account.
$ mailx -s "test" abc@gmail.com
This is unproblematic electronic mail without attachment
EOT
This volition shipping a shipping an electronic mail alongside plain of study every bit "test" to recipient abc@gmail.com. Once you lot type this ascendency it volition inquire you lot to type the content inwards the body. Once you lot are done, you lot tin press the Ctrl + D to halt the typing together with it volition shipping the email.
Btw, If you lot are non familiar alongside Linux operating organization together with compaction itself then Learn Linux inwards v Days together with Level Up Your Career on Udemy is a expert place, to get down with.
The output of echo tin live on used every bit the trunk every bit shown below:
$ echo "testing" | mailx -s "test" abc@gmail.com
This fourth dimension mailx volition non hold off for your input together with volition straight shipping the electronic mail alongside text "texting" inwards the body.
Btw, if you lot are non familiar alongside essential Linux commands together with compaction built-ins similar echo so I propose you lot to commencement acquire through Learn Basic Commands inwards Linux Shell to familiarize yourself alongside these basics commands.
$ gzip -c log.txt | uuencode log.gz | post service -s "log file for `date`" abc@gmail.com
This ascendency volition commencement compress the log.txt together with so volition shipping every bit attachment log.gz alongside plain of study "log file for a date" to abc@gmail.com, hither appointment volition live on replaced yesteryear electrical flow appointment because nosotros have got used `date`, which volition execute the appointment ascendency together with position its output here.
The gzip -c command writes output to measure output piece keeping the master copy files unchanged i.e. non changing it every bit log.gz, which it does without -c option. If you lot desire to larn to a greater extent than virtually gzip together with other compression together with archiving ascendency so banking concern fit out the Linux Command Line Basics course of teaching on Udemy. It's available inwards exactly $9.99 inwards Udemy's flash sale.
This ascendency has served me good for a long fourth dimension but unfortunately, it doesn't piece of work inwards RHEL vi hosts. If you lot travail that ascendency on an RHEL vi hosts, instead of receiving an attachment, you lot volition have roughly gibberish inwards electronic mail trunk alongside no attachment.
So, how produce nosotros solve this problem? Is in that location whatsoever other means to shipping an electronic mail to attachment from RHEL vi hosts? Well, yes, we'll operate the mailx ascendency alongside -a flag, which is used to attach a file.
Here is the event of a mailx ascendency to shipping a file every bit an attachment to RHEL vi servers:
$ echo "mailx industrial plant fine inwards RHEL 6" | mailx -s "texting" -a log.gz abc@gmail.com
This volition shipping an electronic mail alongside the trunk every bit "mailx industrial plant fine inwards RHEL 6" together with attachment every bit log.gz alongside the plain of study job every bit "texting".
$ echo "message" | mailx -s "test" -c group@gmail.com -b admin@gmail.com abc@gmail.com
This electronic mail volition live on sent to abc@gmail.com together with cc'd to group@gmail.com together with BCC to admin@gmail.com
The mailx command has several to a greater extent than options but I didn't quest whatsoever to a greater extent than other than these. If you lot desire to explore, you lot tin operate information mailx ascendency to acquire to a greater extent than information virtually mailx. If you lot desire to larn to a greater extent than you lot tin too take Crontab example)10 event of Networking commands inwards Unix (nslookup) 5 Example of kill commands inwards Unix together with Linux (example) VI Editor examples together with tips for beginners (vi examples) How does nslookup ascendency piece of work inwards UNIX? (answer) 10 examples of lsof ascendency inwards Linux? (examples) How to operate the netstat ascendency to detect which procedure is listening on a port? (example) Linux detect + du + grep event (example) 10 Examples of gyre ascendency inwards Linux (cURL) 10 Examples of chmod ascendency inwards Linux (chmod) A Practical Guide to Linux Commands, Editors, together with Shell Programming (guide)
Thanks for reading this article so far. If you lot similar this article together with my explanation of sending electronic mail from a Linux machine so delight percentage alongside your friends together with colleagues.
P. S. - If you lot are looking for roughly gratis online courses to start your Linux journey, you lot should banking concern fit out my listing of Free Linux Courses for Programmers, information technology Professionals, together with System Administrators.
Now, the query is how to shipping an electronic mail from Linux? together with to a greater extent than importantly how to shipping an electronic mail alongside attachments? Well, in that location are unlike options based on whether you lot are running on RHEL v or RHEL 6.
For example, my favorite means to shipping an electronic mail alongside attachment was yesteryear using the uuencode together with mail ascendency but, unfortunately, that didn't piece of work when nosotros migrated to RHEL 6. So, I had to operate the mailx command alongside -a flag for attachments.
But, mailx is non the alone means to shipping electronic mail from Linux, you lot tin too operate the mutt ascendency if its available to you.
In this article, I'll demo you how to shipping an electronic mail alongside trunk together with attachment using mailx together with mutt ascendency from a Linux host.
There may live on a duo of to a greater extent than options but I haven't explored much, for me these ii industrial plant fine inwards both RHEL v together with RHEL vi hosts together with I was able to complete my scripts alongside these ii commands. I'll explore to a greater extent than when I acquire roughly fourth dimension but if you lot have got roughly thoughts experience gratis to percentage alongside us together with if you lot desire to larn more, I propose you lot acquire through Linux Administration Bootcamp course on Udemy.
How to shipping an electronic mail alongside trunk together with attachment from Linux
I by together with large operate mailx for sending emails, therefore most of the examples are of mailx command. It's too of import to know the syntax of the mailx command, which volition attention you lot to empathise the examples every bit nosotros motion 1 measurement at a time.Syntax of mailx ascendency :
mailx -eiIUdEFntBDNHRV -T FILE -u USER -h hops -r address -s SUBJECT -a FILE -q FILE -f FILE -A ACCOUNT -b USERS -c USERS -S OPTION users
You tin run into that -s is used for a plain of study together with -a is used for attachment. You tin too CC users using -c options together with BCC users using -b option.
Now, 1 question, which may come upward to your heed is what would live on the sender's electronic mail address when you lot shipping post service from Linux? Well, it depends on the user who is sending an email.
For example, if you lot log inwards using your personal operate together with shipping post service so it would live on your electronic mail but if you lot log inwards every bit application user together with shipping an electronic mail so it would live on the electronic mail configured for that application user account.
Example 1 - Sending electronic mail from Linux
If you lot exactly desire to shipping a unproblematic electronic mail e.g. without attachment, you lot tin exactly operate the mailx ascendency to produce that.$ mailx -s "test" abc@gmail.com
This is unproblematic electronic mail without attachment
EOT
This volition shipping a shipping an electronic mail alongside plain of study every bit "test" to recipient abc@gmail.com. Once you lot type this ascendency it volition inquire you lot to type the content inwards the body. Once you lot are done, you lot tin press the Ctrl + D to halt the typing together with it volition shipping the email.
Btw, If you lot are non familiar alongside Linux operating organization together with compaction itself then Learn Linux inwards v Days together with Level Up Your Career on Udemy is a expert place, to get down with.
Example 2 - Writing trunk using echo
In the concluding example, you lot quest to write the content of the trunk together with so press the Ctrl + D to shipping the email, but if you lot already have got a message written you lot tin too operate echo ascendency along alongside mailx to shipping the electronic mail directly.The output of echo tin live on used every bit the trunk every bit shown below:
$ echo "testing" | mailx -s "test" abc@gmail.com
This fourth dimension mailx volition non hold off for your input together with volition straight shipping the electronic mail alongside text "texting" inwards the body.
Btw, if you lot are non familiar alongside essential Linux commands together with compaction built-ins similar echo so I propose you lot to commencement acquire through Learn Basic Commands inwards Linux Shell to familiarize yourself alongside these basics commands.
Example iii - Email alongside Attachment from Linux
This is the most pop operate of mailx ascendency for me. I ever detect using this pick live on it sending a file from Linux host to my windows host or writing scripts which sends electronic mail from a Linux machine. Until RHEL 5, my favorite means to shipping an attachment inwards the electronic mail was yesteryear using the uuencode ascendency e.g.$ gzip -c log.txt | uuencode log.gz | post service -s "log file for `date`" abc@gmail.com
This ascendency volition commencement compress the log.txt together with so volition shipping every bit attachment log.gz alongside plain of study "log file for a date" to abc@gmail.com, hither appointment volition live on replaced yesteryear electrical flow appointment because nosotros have got used `date`, which volition execute the appointment ascendency together with position its output here.
The gzip -c command writes output to measure output piece keeping the master copy files unchanged i.e. non changing it every bit log.gz, which it does without -c option. If you lot desire to larn to a greater extent than virtually gzip together with other compression together with archiving ascendency so banking concern fit out the Linux Command Line Basics course of teaching on Udemy. It's available inwards exactly $9.99 inwards Udemy's flash sale.
This ascendency has served me good for a long fourth dimension but unfortunately, it doesn't piece of work inwards RHEL vi hosts. If you lot travail that ascendency on an RHEL vi hosts, instead of receiving an attachment, you lot volition have roughly gibberish inwards electronic mail trunk alongside no attachment.
So, how produce nosotros solve this problem? Is in that location whatsoever other means to shipping an electronic mail to attachment from RHEL vi hosts? Well, yes, we'll operate the mailx ascendency alongside -a flag, which is used to attach a file.
Here is the event of a mailx ascendency to shipping a file every bit an attachment to RHEL vi servers:
$ echo "mailx industrial plant fine inwards RHEL 6" | mailx -s "texting" -a log.gz abc@gmail.com
This volition shipping an electronic mail alongside the trunk every bit "mailx industrial plant fine inwards RHEL 6" together with attachment every bit log.gz alongside the plain of study job every bit "texting".
Example four - Adding a User together with CC together with BCC
If you lot have got to include other electronic mail address or user every bit CC or BCC piece sending reports from Linux so you lot tin operate the mailx -c together with mailx -b for adding users every bit shown inwards the next example:$ echo "message" | mailx -s "test" -c group@gmail.com -b admin@gmail.com abc@gmail.com
This electronic mail volition live on sent to abc@gmail.com together with cc'd to group@gmail.com together with BCC to admin@gmail.com
The mailx command has several to a greater extent than options but I didn't quest whatsoever to a greater extent than other than these. If you lot desire to explore, you lot tin operate information mailx ascendency to acquire to a greater extent than information virtually mailx. If you lot desire to larn to a greater extent than you lot tin too take Crontab example)
Thanks for reading this article so far. If you lot similar this article together with my explanation of sending electronic mail from a Linux machine so delight percentage alongside your friends together with colleagues.
P. S. - If you lot are looking for roughly gratis online courses to start your Linux journey, you lot should banking concern fit out my listing of Free Linux Courses for Programmers, information technology Professionals, together with System Administrators.
No comments:
Post a Comment