Tuesday, March 10, 2009

Sending mail with attachement

sending mail with one or more attachment can be done with the help of Linux command: 'MUTT'
Steps to work with this commands:
Step 1: Install
# yum -y install mutt

Step 2: Run command on your Shell prompt:
mutt -s 'Test mail' -a file1.xls -a file2.xls username@abc.com -c user2@abc.com < file.txt

you will get test mail with sender info options
From : 'root'
To: username@abc.com
CC: user2@abc.com
Subject: Test mail
Mail Format: file.txt

Above command is useful for me in C programming, to attache multiple files.

Sample code of test.c using this commands:

#include "stdio.h"
int main()
{
system("mutt -s 'Test mail' -a file1.xls -a file2.xls username@abc.com -c user2@abc.com < file.txt");
printf("Mail Sent\n");
return 0;
}

Run test.c
# gcc test.c -o test
#./test
output:
Mail Sent

after complete whole process, one thing is remaining i.e. change of from option
it's should be sender mail_id[name].it 's possible with configuration file .muttrc
following steps:
Steps 1: Create .muttrc file in /$HOME/ directory
Strep 2: open file and write ---
set from="User "

Step 3: save .muttrc file and run test.c file again
you will get desired output as you want...
I hope you will enjoy throughout the whole process... :)

No comments :