Automating Mail Process


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Automating Mail Process
# 1  
Old 07-28-2016
Linux Automating Mail Process

Hi
i had written one script,it sends email from terminal and mine script is as:
Code:
#!/bin/bash
SUBJECT="linux mail send attachment example"
BODY_FILE="/home/sreenivasa/Desktop/Testing.txt"
#ATTACHMENT_FILE="/home/sreenivasa/Desktop/Dataset.zip"
CC_LIST="rajnikant875@gmail.com,sinha6315@gmail.com,rajnikant@gytechs.com"

cat "$BODY_FILE" | mail -s "$SUBJECT" -a "$ATTACHMENT_FILE" "$CC_LIST"

but here problem for me is i can attach only one attachment.But my requirement is all attachment file is in one folder without changing script again and again,how can i access those files from folder which is saved somewhere on Desktop.

So,we have to write script once and when we ran script it should ask for which all file it want to attach into script.Can anyone help me.


Moderator's Comments:
Mod Comment Use code tags, thanks.

Last edited by zaxxon; 07-28-2016 at 08:02 AM..
# 2  
Old 07-28-2016
Use for-loop. But I suppose you would want to change the email body and subject per attachment. I leave it to you to figure it out.

Code:
for ATTACHMENT_FILE in /path/to/folder/* # assuming folder has only files that are to be attached. Tweak accordingly.
do
    SUBJECT="linux mail send attachment example"
    BODY_FILE="/home/sreenivasa/Desktop/Testing.txt"
    CC_LIST="rajnikant875@gmail.com,sinha6315@gmail.com,rajnikant@gytechs.com"
    cat "$BODY_FILE" | mail -s "$SUBJECT" -a "$ATTACHMENT_FILE" "$CC_LIST"
done

This User Gave Thanks to balajesuri For This Post:
# 3  
Old 07-28-2016
A minor tip - remove the useless use of cat

change
Code:
cat "$BODY_FILE" | mail -s "$SUBJECT" -a "$ATTACHMENT_FILE" "$CC_LIST"

to
Code:
mail -s "$SUBJECT" -a "$ATTACHMENT_FILE" "$CC_LIST" < $BODY_FILE


Last edited by frank_rizzo; 07-28-2016 at 02:27 PM.. Reason: corrected spacing
This User Gave Thanks to frank_rizzo For This Post:
# 4  
Old 07-29-2016
What have you tried so far for research? This is a fairly common question with lots of threads in various forums.

This might help:- Unix multiple attachment

I hope that this helps. Let us know how you get on and if you are still stuck.




Robin
This User Gave Thanks to rbatte1 For This Post:
# 5  
Old 07-29-2016
Automating Mail Process

Hi
my script can send mail and attachment without any issue.The problem i am facing is that:there are folder assume at Desktop which has multiple files e.g. pdf,zip,txt,jpg...e.t.c.So, How my script should incorporate all these files automatically.
Here i am thinking assigning all these attachment to one variable name and just by calling that variable in script should work.Good or bad,please share your thoughts.Thank u.
# 6  
Old 07-29-2016
Hi rajnikant,

this answer may help you a lot: https://www.unix.com/302978324-post4.html

regards,
stomp
These 2 Users Gave Thanks to stomp For This Post:
# 7  
Old 07-29-2016
Are you saying that you need help to attach all the files from the a directory, number unknown?

If so, then you will need a loop inside the section of you script that sends the note.

Before we get to that, can you send 2 or 3 attachments in a single note from a script yet? It's important to understand how you feel comfortable doing it before we proceed else you might end up with something you don't understand which is a nightmare to support or adjust if needed.

Paste your code in CODE tags so it is clear to see.



Kind regards,
Robin
This User Gave Thanks to rbatte1 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Automating an interactive process with EOF string

Hello, I'm running Stockfish chess engine ( Home - Stockfish - Open Source Chess Engine ) CLI on Linux in interactive mode which is working fine. root@ubuntu1950x:~# ./stockfish Stockfish 080218 64 POPCNT by T. Romstad, M. Costalba, J. Kiiski, G. Linscott setoption name Debug Log File... (2 Replies)
Discussion started by: prvnrk
2 Replies

2. UNIX for Dummies Questions & Answers

Automating a process

Could any one tell me , how to start a thread here, i just searching for so long. sorry to post in irrelavent here ---------- Post updated at 08:19 AM ---------- Previous update was at 08:00 AM ---------- Hi, I got a requirement to automate the process. We have SLA files, there are... (1 Reply)
Discussion started by: afahmed
1 Replies

3. Shell Programming and Scripting

Automating The process

Hi Guru's, I am trying to write a scripts that will automate my image provisoining process. Scenario: I have Linux Image Hosted on cloud which needs to be provisoned before it can be used. Currently we log onto the image through the putty on windows and connect to linux instance. I... (3 Replies)
Discussion started by: taqvia
3 Replies

4. Shell Programming and Scripting

automating daily monitoring process

Hi there, I have to automate daily monitoring process and then the result of these process should be sent to a log file, then this log file should be mailed . ps -ef | grep aa In this atleast one process should run. If the process is running it should mention Success in the log file... (3 Replies)
Discussion started by: NehaKrish
3 Replies

5. Shell Programming and Scripting

script to monitor process running on server and posting a mail if any process is dead

Hello all, I would be happy if any one could help me with a shell script that would determine all the processes running on a Unix server and post a mail if any of the process is not running or aborted. Thanks in advance Regards, pradeep kulkarni. :mad: (13 Replies)
Discussion started by: pradeepmacha
13 Replies

6. Shell Programming and Scripting

Issue in mail sending process

Hi I created one CSV file and i need to append some message in the content of my mail. $sales=sales.dat $sales_csv=sales.csv $sales_report=sales.txt this is the command am using it. echo "sales for `date`"| read subject uuencode $sales $sales_csv | mailx -ms "${subject}."... (2 Replies)
Discussion started by: bobprabhu
2 Replies

7. Shell Programming and Scripting

Killing of a process and send a mail if the process doesnot come up within 2 minutes

Hi Friends, I am new to this forum as well as new to shell scripting. I have a problem here and i need someone to solve this. Let us consider there are two processes(abc & def).There is a script which kills these two processes(i.e killtheprocess abc). Here abc is the argument . There is a... (1 Reply)
Discussion started by: Prince89
1 Replies

8. Linux

Automating build and test process

Hey ppl, I've been asked to automate the build and test process for my team at office.we work on Linux and use Perforce for SCM. I've just joined this company and dont have much knowledge on unix scripts. Could someone tell me how to go about doing this?:confused: (8 Replies)
Discussion started by: laxmi
8 Replies

9. Shell Programming and Scripting

Automating build and test process

Hey ppl, I've been asked to automate the build and test process for my team at office.we work on Linux and use Perforce for SCM. I've just joined this company and dont have much knowledge on unix scripts. Could someone tell me how to go about doing this? (0 Replies)
Discussion started by: laxmi
0 Replies

10. UNIX for Dummies Questions & Answers

Process mail using cron

I am looking for information on how to process mail using a cron job. The email server is a hosted ISP, so I simply have a POP connection to the mailbox. Specifically, I want to fire a cron job at {x} time and have pine, mail, mailx, or some other suitable mail client utility process the... (1 Reply)
Discussion started by: EOD
1 Replies
Login or Register to Ask a Question