Automating Mail Process


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Automating Mail Process
# 15  
Old 08-01-2016
Automating Mail Process

Hi Don Cragun

1. i ran the script with echo keyboard inside the script as u instructed and it is unable to send the mail,it just displays the files inside that Folder.
Code:
/sreenivasa@UIPL08:~/Desktop$ ./Experiment1.sh
#mail -s linux mail send attachment example  -a "/home/sreenivasa/Desktop/ATTACH/Arduino.doc" -a "/home/sreenivasa/Desktop/ATTACH/Bug.jpg" -a "/home/sreenivasa/Desktop/ATTACH/Bugzilla.pdf" -a "/home/sreenivasa/Desktop/ATTACH/Dataset.zip" -a "/home/sreenivasa/Desktop/ATTACH/diet.jpg" -a "/home/sreenivasa/Desktop/ATTACH/Raj.txt" -a "/home/sreenivasa/Desktop/ATTACH/RFQ.xlsx"  rajnikant875@gmail.com,sinha6315@gmail.com,rajnikant@gytechs.com

2. And when i use the same script with single attachment it will send mail with that particular attachment.

3. When i ran same script without echo keyword,it displays output something as:
Code:
sreenivasa@UIPL08:~/Desktop$ ./Experiment1.sh
 -a "/home/sreenivasa/Desktop/ATTACH/Arduino.doc" -a "/home/sreenivasa/Desktop/ATTACH/Bug.jpg" -a "/home/sreenivasa/Desktop/ATTACH/Bugzilla.pdf" -a "/home/sreenivasa/Desktop/ATTACH/Dataset.zip" -a "/home/sreenivasa/Desktop/ATTACH/diet.jpg" -a "/home/sreenivasa/Desktop/ATTACH/Raj.txt" -a "/home/sreenivasa/Desktop/ATTACH/RFQ.xlsx": No such file or directory

4. i tried using mailx,uuencode but none of them are working with multiple attachment.But for loop is able to attach all the files from ATTACHMENTS folder.

5. Please share your input.


Thank U
Rajnikant

---------- Post updated at 10:38 AM ---------- Previous update was at 10:36 AM ----------

The code which i am using is:
Code:
/#!/bin/bash
ATTACHMENT_DIR="/home/sreenivasa/Desktop/ATTACH"
ATTACHMENTS=
BODY_FILE="/home/sreenivasa/Desktop/Testing.txt"
SUBJECT="linux mail send attachment example"
TO_LIST="rajnikant875@gmail.com,sinha6315@gmail.com,rajnikant@gytechs.com"

# Gather list of attachments:
for file in "$ATTACHMENT_DIR"/*
do    [ ! -f "$file" ] && continue
    ATTACHMENTS="$ATTACHMENTS -a \"$file\""
done

# Send the message.
mail -s "$SUBJECT"  "$ATTACHMENTS" "$TO_LIST" < "$BODY_FILE"


Last edited by Don Cragun; 08-01-2016 at 01:11 PM.. Reason: Fix CODE tags and and ICODE tags.
# 16  
Old 08-01-2016
Sorry. My mistake. There should not be double quotes around the expansion of $ATTACHMENTS in the mail command. Please try this:
Code:
mail -s "$SUBJECT"  $ATTACHMENTS "$TO_LIST" < "$BODY_FILE"

instead of:
Code:
mail -s "$SUBJECT"  "$ATTACHMENTS" "$TO_LIST" < "$BODY_FILE"

# 17  
Old 08-02-2016
Automating Mail Process

Hi Don Cragun
Case1: i used the
Code:
mail -s "$SUBJECT"  $ATTACHMENTS "$TO_LIST" < "$BODY_FILE"

Output i am getting is like this on console:
Code:
sreenivasa@UIPL08:~/Desktop$ sudo ./Experiment1.sh
"/home/sreenivasa/Desktop/ATTACH/Arduino.doc": No such file or directory

Case2: When i use
Code:
mail -s "$SUBJECT"  "$ATTACHMENTS" "$TO_LIST" < "$BODY_FILE"

Then it would send mail without any attachment,i had attached one snapshot of that.please have a look.

Thanks
Rajnikant



Moderator's Comments:
Mod Comment Please use code tags correctly!
Automating Mail Process-attachpng

Last edited by RudiC; 08-02-2016 at 04:27 AM.. Reason: Repaired CODE tags.
# 18  
Old 08-02-2016
Quote:
Originally Posted by rajnikant
Hi Don Cragun
Case1: i used the
Code:
mail -s "$SUBJECT"  $ATTACHMENTS "$TO_LIST" < "$BODY_FILE"

Output i am getting is like this on console:
Code:
sreenivasa@UIPL08:~/Desktop$ sudo ./Experiment1.sh
"/home/sreenivasa/Desktop/ATTACH/Arduino.doc": No such file or directory

Case2: When i use
Code:
mail -s "$SUBJECT"  "$ATTACHMENTS" "$TO_LIST" < "$BODY_FILE"

Then it would send mail without any attachment,i had attached one snapshot of that.please have a look.

Thanks
Rajnikant



Moderator's Comments:
Mod Comment Please use code tags correctly!
Automating Mail Process-attachment-failpng
# 19  
Old 08-02-2016
Automating Mail Process

Hi rabatte
Script is able to send mail with single attachment but when it comes to multiple attachments.it is unable to do so.Have a look and share your thoughts.

Code which i am using is code:
Code:
#!/bin/bash ATTACHMENT_DIR="/home/sreenivasa/Desktop/ATTACH"  ATTACHMENTS= BODY_FILE="/home/sreenivasa/Desktop/Testing.txt"  SUBJECT="linux mail send attachment example"  TO_LIST="rajnikant875@gmail.com,sinha6315@gmail.com,rajnikant@gytechs.com"   # Gather list of attachments: for file in "$ATTACHMENT_DIR"/* do    [ !  -f "$file" ] && continue     ATTACHMENTS="$ATTACHMENTS -a  \"$file\"" done  # Send the message. mail -s "$SUBJECT"  $ATTACHMENTS  "$TO_LIST" < "$BODY_FILE"

Thanks
Rajnikant

---------- Post updated at 07:44 AM ---------- Previous update was at 07:14 AM ----------

Quote:
Originally Posted by balajesuri
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

Hi balajesuri
for loop is working but it is sending all the attachment one by one.Can we modify it in a way that it send all the attachment in a single mail.please share your thought.

Thanks
Rajnikant

---------- Post updated at 07:50 AM ---------- Previous update was at 07:44 AM ----------

Hi Don Cragun
Here is another piece of code but problem here is, it send all attachments one by one, not all at time.
Code:
#!/bin/bash
for ATTACHMENT_FILE in /home/sreenivasa/Desktop/ATTACHMENTS/* 
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"
    mail -s "$SUBJECT" -a $ATTACHMENT_FILE "$CC_LIST" < "$BODY_FILE" 
done

Can u share your idea to make it better.
Thanks
Rajnikant

Last edited by rajnikant; 08-02-2016 at 09:22 AM..
# 20  
Old 08-02-2016
OK. I understand what I did wrong, but my problem is that when you have filenames like RFQ - Medical - 15-05- 2016.xlsx (containing whitespace characters) we have to quote the filename to keep it from being treated as six separate files, but gathering a group of quoted strings in a variable and expanding that variable ends up with the quotes being part of the filename.

Can you rename your attachment files so that they do not include any spaces or tabs before you call this script?

If not, do you mind if the script renames the files in the attachments directory (and leaves them with new names not containing spaces or tabs)? (Note that if any of the directories in the pathname of you attachments directory contain any whitespace characters, I am not offering to make a script for you that will work in those circumstances!)
This User Gave Thanks to Don Cragun For This Post:
# 21  
Old 08-02-2016
Automating mail process

HI
i would not mind renaming Folder name or script renaming the files in the attachments directory.i already renamed this particular file from
Code:
RFQ - Medical - 15-05- 2016.xlsx (containing whitespace characters)

to just RFQ.xlsx
But still it is unable to send the attachment.Please share your input.

Thanks
Rajnikant
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