Send file linux mail

sending file using sendmail

It gets executed whenever I call this function. Now I have a text file which I want to send using sendmail as attachment or as message in the email it sends. How can I do that? I have tried alot of tricks but nothing seems to work. Please Help.

5 Answers 5

Type uuencode /path/filename.txt | sendmail -s «subject» user@domain in your terminal to send mail.

  • Replace «path» with the actual directory path in which the file to attach is located.
  • Replace «filename.ext» with the actual file name and extension.
  • Replace «subject» with the subject line you want the email to have.
  • Replace «user@domain» with the recipient’s email address.

this is the actual process to send mail with attachment.

add uuencode /path/filename.txt before sendmail command in your script. I mean modify it as

I tried the approach but when executing the script it gives the message begin 644 /path/filename.txt and the cursor keeps on blinking.

I have created below script to attach a CSV File. The File is getting generated, but its truncating the header row /column name of CSV incorrectly and also there is one more file thats getting attached with the email, namely ‘ATT0001.txt’ with every email. Anything wrong that you could found out here?

SCRIPT

( echo "From:"$1; echo "To:"$2; echo "Subject:"$3; echo "MIME-Version: 1.0"; echo "Content-Type:multipart/mixed; boundary=\"B835649000072104Jul07\""; echo "--B835649000072104Jul07"; echo "Content-Type: text/html; charset=\"UTF-8\""; echo "Content-Transfer-Encoding: 7bit"; echo "Content-Disposition: inline"; echo ""; echo "$4"; echo "--B835649000072104Jul07"; echo "Content-Type: text/csv"; echo "Content-Transfer-Encoding: base64"; echo "Content-Disposition: attachment; filename=\"$5\""; base64 "$5" echo "--B835649000072104Jul07"; ) | sendmail -t 

Источник

4 Ways to Send Email Attachment from Linux Command Line

Once you get familiar to using the Linux terminal, you wish to do everything on your system by simply typing commands including sending emails and one of the important aspects of sending emails is attachments.

Читайте также:  Astra linux virt manager access denied

Especially for Sysadmins, can attach a backup file, log file/system operation report or any related information, and send it to a remote machine or workmate.

In this post, we will learn ways of sending an email with attachment from the Linux terminal. Importantly, there are several command line email clients for Linux that you can use to process emails with simple features.

Requirement

To effectively and reliably use this tutorial, you must have a working mail system or setup one of the mail transfer agents (MTA’s) for Linux on your system.

A MTA is an application responsible for sending and receiving emails from one host to another.

Below are the various, well known methods of sending email with attachment from the terminal.

1. Using mail Command

mail is part of the mailutils (On Debian) and mailx (On RedHat) package and it is used to process messages on the command line.

$ sudo apt-get install mailutils # yum install mailx

Now its time to send an email attachment using mail command a shown.

In the above command, the flag:

You can as well send an existing message from a file as follows:

2. Using mutt Command

mutt is a popular, lightweight command line email client for Linux.

If you do not have it on your system, type the command below to install it:

$ sudo apt-get install mutt # yum install mutt

You can send an email with attachment using the mutt command below.

3. Using mailx Command

mailx works more like the mutt command and it it also a part of mailutils (On Debian) package.

$ sudo apt-get install mailutils # yum install mailx

Now send the attachment mail from the command-line using mailx command.

4. Using mpack Command

mpack encodes the named file in one or more MIME messages and sends the message to one or more recipients, or writes it to a named file or set of files, or posts it to a set of newsgroups.

$ sudo apt-get install mpack # yum install mpack

To send a message with attachment, run the command below.

That’s all! Do you have in mind any other methods of sending emails with attachment from the Linux terminal, that are not mentioned in the list above? Let us know in the comments.

Читайте также:  Astra linux сетевая печать

Источник

How can I send a file from Linux to email? [duplicate]

How can I send a zip file (~600MB) to an email account? What is the command line should be used in bash? What if I want to FTP the files to a server automatically?

I wanted to close because it’s a duplicate, but I missed the link and now I cannot change it. SO needs UI fix 😉

3 Answers 3

Well, in my opinion 600Mb is too large for e-mail, since some clients and servers will choke on that size. But that’s your choice, and if you own the webserver then obviously you can do what you like.

The unix command mail can be used (when configured) to send emails.

You might also want to look at perl’s Net::SMTP module, which is for this sort of thing.

Most linux distributions contain a mail command (from the mailx package). You can attach a file from the command line using the -a option:

mail -s 'file attached' -a /path/to/file someone@example.com 

That said, most mail systems won’t be happy with 600MB attachments.

The ncftp package has a number of commands that may be useful for automated transferring of files over FTP, in particular the ncftpput command (see the manpages for more information).

Depending on where you are sending the file, if the other end supports ssh, it might be better to use tools like scp or ssh and rsync. With public key authentication, you don’t even have to worry about embedding a password anywhere.

If you are doing backups, consider a tool like Duplicity (but not for a full zip file as it loses most of its advantages) as it supports a number of protocols, performs compression on-the-fly and can perform incremental backups. Oh, and the backups are encrypted and digitally signed to ensure their integrity.

Источник

How to Send An Email With File Attachment from Command Line

The key to becoming an advanced Linux user is to use more of the command line and less of the GUI; more of the keyboard and less of the mouse! As the diaspora of Linux command-line tools grows, not only administrative but several non-administrative, in fact, crucial day-to-day tasks, are performed using the command line.

Читайте также:  Лав linux системное программирование

In this article, we will learn how to send an email with a file attachment using the mail command in Linux.

Pre-Requisites

You must have already configured your Email with SMTP in your Linux machine. This Email and server will be made use of by the ‘Mail‘ program which we will learn about today.

Sending an Email from Command Line in Linux

The program ‘mail’ can be used to send an Email from the command line, along with file attachments with the Email. This program is not available by default, and can be installed in Debian and Red Hat-based distributions using:

$ sudo apt install mailutils [On Debian/Ubuntu/Mint] $ sudo dnf install mailx [On RedHat/CentOS/Fedora]

The syntax to send an Email using ‘mail’ is as follows:

You can see that we are using the echo command to output the message body and redirecting this output to the ‘mail’ command. This is because the ‘mail’ command reads message body input from the standard input.

Sending an Email with File Attachment from Command Line

Similarly, to attach a file with the mail, the argument ‘-A’ can be used:

Send an Email with File Attachement from Terminal

Sending an Email to Multiple Recipients from Command Line

To send the email to multiple recipients, simply specify the multiple Email IDs separated by a comma.

$ echo «Email Message Body» | mail -s «Subject of the Email» [email protected];[email protected],[email protected] -A

Send Email to Multiple Recipients

To include a text file as the message body of the Email, instead of using echo for the same, you can redirect the text of a file to the command as shown below:

Conclusion

Today we have seen a way to send an Email from the Linux command line along with an attachment. There are some other programs like ‘mutt‘ and ‘Sendmail‘ which are similar to ‘mail‘ and can be used for the same purpose.

Thanks for reading and let us know your thoughts or questions in the comments below!

Источник

Оцените статью
Adblock
detector