Linux Mailx + Mutt Ascendancy Examples - Four Ways To Ship Electronic Mail Amongst Attachment From Rhel V Too Half Dozen Server

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 five or RHEL half dozen version in addition to you lot involve to shipping a written report of all the clients connecting to your application. An tardily agency to make this is to write a shell script, which volition dump all clients inwards the log file in addition to so purpose grep command in addition to generate a report. If you lot have got to grep logs from multiple hosts, you lot tin likewise purpose the SSH dominance to run the same dominance on multiple hosts. Once you lot have got got the listing of clients connecting to your application, you lot tin precisely 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 interrogation is how to shipping an electronic mail from Linux? in addition to to a greater extent than importantly how to shipping an electronic mail amongst attachments? Well, in that location are dissimilar options based on whether you lot are running on RHEL five or RHEL 6.

For example, my favorite agency to shipping an electronic mail amongst attachment was yesteryear using the uuencode in addition to mail dominance but, unfortunately, that didn't operate when nosotros migrated to RHEL 6. So, I had to purpose the mailx command amongst -a flag for attachments.

But, mailx is non the entirely agency to shipping electronic mail from Linux, you lot tin likewise purpose the mutt dominance if its available to you.

In this article, I'll demonstrate you how to shipping an electronic mail amongst torso in addition to attachment using mailx in addition to mutt dominance from a Linux host. 

There may hold out a twain of to a greater extent than options but I haven't explored much, for me these ii plant fine inwards both RHEL five in addition to RHEL half dozen hosts in addition to I was able to complete my scripts amongst these ii commands. I'll explore to a greater extent than when I acquire precisely about fourth dimension but if you lot have got precisely about thoughts experience gratis to portion amongst us in addition to if you lot desire to acquire more, I advise you lot become through Linux Administration Bootcamp course on Udemy.




How to shipping an electronic mail amongst torso in addition to attachment from Linux

I to a greater extent than oftentimes than non purpose mailx for sending emails, so most of the examples are of mailx command. It's likewise of import to know the syntax of the mailx command, which volition help you lot to empathise the examples every bit nosotros motion 1 measuring at a time.

Syntax of mailx dominance :

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 come across that -s is used for a dependent champaign in addition to -a is used for attachment. You tin likewise CC users using -c options in addition to BCC users using -b option.

Now, 1 question, which may come upwards to your heed is what would hold out the sender's electronic mail address when you lot shipping send service from Linux? Well, it depends on the user who is sending an email.

For example, if you lot log inwards using your personal purpose in addition to shipping send service so it would hold out your electronic mail but if you lot log inwards every bit application user in addition to shipping an electronic mail so it would hold out the electronic mail configured for that application user account.


Example 1 - Sending electronic mail from Linux

If you lot precisely desire to shipping a uncomplicated electronic mail e.g. without attachment, you lot tin merely purpose the mailx dominance to produce that.

$ mailx -s "test" abc@gmail.com
This is uncomplicated electronic mail without attachment
EOT

This volition shipping a shipping an electronic mail amongst dependent champaign every bit "test" to recipient abc@gmail.com. Once you lot type this dominance 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 goal the typing in addition to it volition shipping the email.

Btw, If you lot are non familiar amongst Linux operating arrangement in addition to trounce itself then Learn Linux inwards five Days in addition to Level Up Your Career on Udemy is a proficient place, to laid out with.

 One of the mutual chore for programmers working inwards Linux machine is to shipping emails Linux mailx  + mutt dominance Examples - four ways to shipping Email amongst Attachment from RHEL five in addition to half dozen Server


Example 2 - Writing torso using echo

In the concluding example, you lot involve to write the content of the torso in addition to so press the Ctrl + D to shipping the email, but if you lot already have got a message written you lot tin likewise purpose echo dominance along amongst mailx to shipping the electronic mail directly.

The output of echo tin hold out used every bit the torso every bit shown below:

$ echo "testing" | mailx -s "test" abc@gmail.com

This fourth dimension mailx volition non hold off for your input in addition to volition straight shipping the electronic mail amongst text "texting" inwards the body.

Btw, if you lot are non familiar amongst essential Linux commands in addition to trounce built-ins similar echo so I advise you lot to start become through  Learn Basic Commands inwards Linux Shell to familiarize yourself amongst these basics commands.




Example iii - Email amongst Attachment from Linux

This is the most pop purpose of mailx dominance for me. I ever honor using this pick hold out 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 agency to shipping an attachment inwards the electronic mail was yesteryear using the uuencode dominance e.g.

$ gzip -c log.txt | uuencode log.gz | shipping service -s "log file for `date`" abc@gmail.com


This dominance volition start compress the log.txt in addition to so volition shipping every bit attachment log.gz amongst dependent champaign "log file for a date" to abc@gmail.com, hither appointment volition hold out replaced yesteryear electrical current appointment because nosotros have got used `date`, which volition execute the appointment dominance in addition to pose its output here.

The gzip -c command writes output to touchstone 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 acquire to a greater extent than nearly gzip in addition to other compression in addition to archiving dominance so banking concern gibe out the  Linux Command Line Basics course of study on Udemy.  It's available inwards precisely $9.99 inwards Udemy's flash sale.

 One of the mutual chore for programmers working inwards Linux machine is to shipping emails Linux mailx  + mutt dominance Examples - four ways to shipping Email amongst Attachment from RHEL five in addition to half dozen Server


This dominance has served me good for a long fourth dimension but unfortunately, it doesn't operate inwards RHEL half dozen hosts. If you lot effort that dominance on an RHEL half dozen hosts, instead of receiving an attachment, you lot volition have precisely about gibberish inwards electronic mail torso amongst no attachment.

So, how produce nosotros solve this problem? Is in that location whatever other agency to shipping an electronic mail to attachment from RHEL half dozen hosts? Well, yes, we'll purpose the mailx dominance amongst -a flag, which is used to attach a file.

Here is the instance of a mailx dominance to shipping a file every bit an attachment to RHEL half dozen servers:

$ echo "mailx plant fine inwards RHEL 6" | mailx -s "texting" -a log.gz abc@gmail.com

This volition shipping an electronic mail amongst the torso every bit "mailx plant fine inwards RHEL 6" in addition to attachment every bit log.gz amongst the dependent champaign work every bit "texting".



Example four - Adding a User in addition to CC in addition to 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 purpose the mailx -c in addition to 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 hold out sent to abc@gmail.com in addition to cc'd to group@gmail.com in addition to BCC to admin@gmail.com

The mailx command has several to a greater extent than options but I didn't involve whatever to a greater extent than other than these. If you lot desire to explore, you lot tin purpose information mailx dominance to acquire to a greater extent than information nearly mailx. If you lot desire to acquire to a greater extent than you lot tin likewise take Crontab example)
  • 10 instance of Networking commands inwards Unix (nslookup)
  • 5 Example of kill commands inwards Unix in addition to Linux (example)
  • VI Editor examples in addition to tips for beginners (vi examples)
  • How does nslookup dominance operate inwards UNIX? (answer)
  • 10 examples of lsof dominance inwards Linux? (examples)
  • How to purpose the netstat dominance to honor which procedure is listening on a port? (example)
  • Linux honor + du + grep instance (example)
  • 10 Examples of scroll dominance inwards Linux (cURL)
  • 10 Examples of chmod dominance inwards Linux (chmod)
  • A Practical Guide to Linux Commands, Editors, in addition to Shell Programming (guide)

  • Thanks for reading this article so far. If you lot similar this article in addition to my explanation of sending electronic mail from a Linux machine so delight portion amongst your friends in addition to colleagues.

    P. S. - If you lot are looking for precisely about gratis online courses to start your Linux journey, you lot should banking concern gibe out my listing of Free Linux Courses for Programmers, information technology Professionals, in addition to System Administrators.

    0 Response to "Linux Mailx + Mutt Ascendancy Examples - Four Ways To Ship Electronic Mail Amongst Attachment From Rhel V Too Half Dozen Server"

    Post a Comment

    Iklan Atas Artikel

    Iklan Tengah Artikel 1

    Iklan Tengah Artikel 2

    Iklan Bawah Artikel