Email with attachment from local machine through UNIX


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Email with attachment from local machine through UNIX
# 1  
Old 01-13-2015
Question Email with attachment from local machine through UNIX

Hello everyone,
So, here is my requirement.
I want to run an SQL query and export the result in an excel file and send that as an attachement in an email to the intended receipients.

Please help me understand how to do that.
How to connect to database, how to export the output in an excel file and how to attach it to an email and send it.

Also let me know if a file from local machine can be attached and sent through email by a unix/linux command.

P.S: I am a beginner in UNIX/Linux.

Thanks in advance Smilie

Last edited by Mohdrafi12; 01-13-2015 at 09:53 AM..
# 2  
Old 01-13-2015
find yourself a copy of metamail. Some distros of Linux don't supply metamail anymore, but at the same time, they don't seem to be supplying an alternative either.
# 3  
Old 01-13-2015
You're asking 3 questions.

SQL query
Send as attachment
Import into Excel

This depends on the SQL client you're using; however, mostly every SQL UNIX client can do something like this, here is an example using mySql.
I have a file that contains my sql statements: my.sql.query.file and I save the results in file saved.query.txt (this is not the only way to run sql commands from the command )...

Code:
mysql -b -u username -p password <my.sql.query.file > saved.query.txt

Note: the use of the -b switch will use tab as the delimiter between fields in the saved.query.txt file. You will have to consult your sql client to see if you can specify an output field delimeter. I think the default for mysql is comma with field enclosed in "

Sending attachments in email can be done in this fashion (this is
the traditional way of sending attachments...

Code:
uuencode saved.query.txt saved.query.txt | mail user@somehost.org

Since I used the -b option on my output file, I simply import it into excel asking it to use tab as the delimeter.
# 4  
Old 01-13-2015
What you are asking is to basically design and code an application.

I'm providing you what you asked directly, we are not a coding service.
You are asking:
how to email a file as an attachment
Oracle with a tab delimited csv file:
Code:
sqlplus -s user/passwd@instance <<EOF
set colsep '   '   -- there is a tab character between the  ' '
spool file.csv
@some_sql_report_someone_wrote.sql
spool off
EOF

email:
Code:
uuencode file.csv file.csv | mailx -s 'Excel format report' somebody@yourcompany.com


Next time please make an effort and show what you did. Give information about your UNIX system and the database: sql server, oracle, db2. This directly answered your questions, but it is next to useless for you, in the same way your question is not useful for us.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Reading the Attachment from UNIX email

Hi - How would you read in the attachment from your unix mail account? The attachment is in BASE64 so I need to isolate those lines so I can convert them. The number of lines varies from a few to a few hundred. To complicate matters, the mail box gets non related emails I want to ignore. The lines... (3 Replies)
Discussion started by: Oliver Burns
3 Replies

2. Shell Programming and Scripting

html format email with attachment in unix

Team, I have the below code, which is working fine and it sends the html report using sendmail command. I want to attach one more file ( which goes as attachment ) in that email. How to achieve it. i tried with uuencode. But no luck :mad: outputFile="/tmp/out.html" ( echo... (2 Replies)
Discussion started by: itkamaraj
2 Replies

3. Shell Programming and Scripting

How to transfer files from unix machine to local machine using shell script?

Hi All.. Am new to Unix!! Am creating a shell script in which a scenario is like i have transfer the output file from unix machine (Server) to local directory (Windows xp). And also i have to transfer the input file from the local directory to Unix machine (Server) Any help from you... (1 Reply)
Discussion started by: vidhyaS
1 Replies

4. Shell Programming and Scripting

UNIX file attachment in email

Hi, I have a syntax for mail attachment as $EMAIL "Wrapper $wrapper_script_name has failed" " $wrapper_script_name has Failed " $failed_email_address and $EMAIL is as below MSGSub=${1} MSGText=${2} RMAIL=${3} #set LANG='' export LANG='' echo "${MSGSub}" | mailx -s "${MSGText}" ... (1 Reply)
Discussion started by: satgur
1 Replies

5. Shell Programming and Scripting

Send email with attachment in form of excel in unix

Hi, I have a shell script which send email with an attachment in the form of an email. However, the when I open the attachment, all the data comes in one column. How do I format the data in the excel sheet while sending the email? Thanks (8 Replies)
Discussion started by: bdebroy
8 Replies

6. Shell Programming and Scripting

send email from unix with attachment

Hello All, This is a common question that I found lot of results in the forums. I am trying to use uuencode to attach a file and send email. I have no issues sending email, but not able to attach any files using sendmail. Is uuencode part of sendmail or does 'uuencode' utility need to be... (1 Reply)
Discussion started by: chiru_h
1 Replies

7. UNIX for Dummies Questions & Answers

unix to Lotus Notes email attachment

Hi all, I have searched the FAQ and find that there is some threads related to this subject. But can you please give an examples on how to send attachment to Lotus Notes email through UNIX? Since i have gone through the RFC and the URL. But i still have no idea on it. Please give some... (7 Replies)
Discussion started by: wilsonchan1000
7 Replies

8. UNIX for Dummies Questions & Answers

unix to Lotus Notes email attachment

We have been trying to get an email from unix to Lotus Notes to work. We finally got it to work with the following code: cat filename | uuencode filename | mailx -s "subject title" email address Now our problem is that Lotus Notes doesn't show the paper clip icon, indicating an attachment... (3 Replies)
Discussion started by: cowgilm
3 Replies

9. How do I send email?

Transfering unix file as an email attachment

I've written a a script which generates a report file, saved to a unix directory. I need to transfer it, via email, to some users. The command I'm using in my script is: (note that subject & cur_address are set in the script prior to this line) cat /u/sandyl/sm_o_commdt_archive/c | uuencode... (3 Replies)
Discussion started by: slivi
3 Replies

10. UNIX for Dummies Questions & Answers

Transfering unix file as an email attachment

I've written a a script which generates a report file, saved to a unix directory. I need to transfer it, via email, to some users. The command I'm using in my script is: (note that subject & cur_address are set in the script prior to this line) cat /u/sandyl/sm_o_commdt_archive/c | uuencode... (3 Replies)
Discussion started by: slivi
3 Replies
Login or Register to Ask a Question