Getting the Attached File in Email


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Getting the Attached File in Email
# 1  
Old 04-19-2016
Getting the Attached File in Email

Hi All,

Is there a way on how to get the attached file in email using shell script? what i'm going to do? all i can see is to send and email but to get an attached file in email i don't find it.

Please advise,

Thanks,
# 2  
Old 04-19-2016
That depends on the mail command you are using; e.g. mutt provides an
Quote:
OPTIONS
-a file
Attach a file to your message using MIME.
while mail/mailx don't.
# 3  
Old 04-19-2016
here's the option that i have when i used man mail

Code:
MAILX(1)                         User Commands                        MAILX(1)

NAME
       mailx - send and receive Internet mail

SYNOPSIS
       mailx [-BDdEFintv~] [-s subject] [-a attachment ] [-c cc-addr] [-b bcc-
              addr] [-r from-addr] [-h hops] [-A account] [-S vari-
              able[=value]] to-addr . . .
       mailx [-BDdeEHiInNRv~] [-T name] [-A account] [-S variable[=value]] -f
              [name]
       mailx [-BDdeEinNRv~] [-A account] [-S variable[=value]] [-u user]

DESCRIPTION
       Mailx is an intelligent mail processing system,  which  has  a  command
       syntax  reminiscent  of  ed(1)  with lines replaced by messages.  It is
       based on Berkeley Mail 8.1, is intended to provide the functionality of
       the  POSIX  mailx  command, and offers extensions for MIME, IMAP, POP3,
       SMTP, and S/MIME.  Mailx provides  enhanced  features  for  interactive
       use,  such  as  caching  and  disconnected  operation for IMAP, message
       threading, scoring, and filtering.  It is also usable as a  mail  batch
       language, both for sending and receiving mail.

       The following options are accepted:

       -A name
              Executes  an  account  command  (see  below)  for name after the
              startup files have been read.

       -a file
              Attach the given file to the message.

       -B     Make standard input and standard output line-buffered.

       -b address
              Send blind carbon copies to list.  List should be a  comma-sepa-
              rated list of names.

       -c address
              Send carbon copies to list of users.

       -D     Start  in disconnected mode; see the description for the discon-
              nected variable option.

       -d     Enables debugging messages and disables the actual  delivery  of
              messages.  Unlike -v, this option is intended for mailx develop-
              ment only.

       -e     Just check if mail is present in the system  mailbox.   If  yes,
              return an exit status of zero, else, a non-zero value.

       -E     If an outgoing message does not contain any text in its first or
              only message part, do not  send  it  but  discard  it  silently,
              effectively   setting  the  skipemptybody  variable  at  program
              startup.  This is  useful  for  sending  messages  from  scripts
              started by cron(8).

       -f [file]
              Read  in the contents of the userâs mbox (or the specified file)
              for processing; when mailx is quit, it writes undeleted messages
              back  to this file.  The string file is handled as described for
              the folder command below.

       -F     Save the message to send in a file named after the local part of
              the first recipientâs address.

       -H     Print header summaries for all messages and exit.

       -h hops
              Invoke  sendmail  with the specified hop count.  This option has
              no effect when SMTP is used for sending mail.
		-i     Ignore tty interrupt signals.  This is particularly useful  when
              using mailx on noisy phone lines.

       -I     Shows  the  âNewsgroup:â  or  âArticle-Id:â fields in the header
              summary.  Only applicable in combination with -f.

       -n     Inhibits reading /etc/mail.rc upon startup.  This option  should
              be activated for mailx scripts that are invoked on more than one
              machine, because the contents of that file  may  differ  between
              them.

       -N     Inhibits  the  initial  display  of message headers when reading
              mail or editing a mail folder.

       -q file
              Start the message with the contents of the specified file.   May
              be given in send mode only.

       -r address
              Sets  the From address. Overrides any from variable specified in
              environment or startup files.  Tilde escapes are disabled.   The
              -r  address options are passed to the mail transfer agent unless
              SMTP is used.  This option exists for compatibility only; it  is
              recommended to set the from variable directly instead.

       -R     Opens any folders read-only.

       -s subject
              Specify  subject  on command line (only the first argument after
              the -s flag is used as a subject; be careful to  quote  subjects
              containing spaces).

       -S variable[=value]
              Sets  the  internal  option  variable  and,  in case of a string
              option, assigns value to it.
			  
		-T name
              Writes the âMessage-Id:â and âArticle-Id:â header fields of each
              message  read  in  the file name.  Implies -I.  Compressed files
              are handled as described for the folder command below.

       -t     The message to be sent is expected to contain a  message  header
              with  âTo:â,  âCc:â,  or  âBcc:â  fields  giving its recipients.
              Recipients specified on the command line are ignored.

       -u user
              Reads the mailbox of the given user name.

       -v     Verbose mode.  The details of  delivery  are  displayed  on  the
              userâs terminal.

       -V     Print mailxâs version and exit.

       -~     Enable tilde escapes even if not in interactive mode.

   Sending mail
       To  send  a  message  to  one or more people, mailx can be invoked with
       arguments which are the names of people to whom the mail will be  sent.
       The  user is then expected to type in his message, followed by an âcon-
       trol-Dâ at the beginning of a line.  The section below Replying  to  or
       originating  mail,  describes  some features of mailx available to help
       when composing letters.

   Reading mail
       In normal usage mailx is given no arguments and checks the userâs  mail
       out  of the post office, then prints out a one line header of each mes-
       sage found.  The current message is initially the first  message  (num-
       bered 1) and can be printed using the print command which can be abbre-
       viated âpâ).  The user can move among the messages  much  as  he  moves
       between  lines in ed(1), with the commands â+â and â-â moving backwards
       and forwards, and simple numbers.
	Disposing of mail
       After examining a message the user can delete âdâ) the message or reply
       ârâ) to it.  Deletion causes the mailx program to forget about the mes-
       sage.  This is not irreversible; the message can be undeleted  âuâ)  by
       giving  its  number,  or the mailx session can be aborted by giving the
       exit âxâ) command.  Deleted messages will, however,  usually  disappear
       never to be seen again.

   Specifying messages
       Commands  such  as print and delete can be given a list of message num-
       bers as arguments to apply to a  number  of  messages  at  once.   Thus
       âdelete  1 2â deletes messages 1 and 2, while âdelete 1-5â deletes mes-
       sages 1 through 5.  In sorted or threaded mode (see the sort and thread
       commands),  âdelete  1-5â deletes the messages that are located between
       (and including) messages 1 through 5 in the sorted/threaded  order,  as
       shown  in  the  header  summary.   The  following special message names
       exist:

       :n     All new messages.

       :o     All old messages (any not in state read or new).

       :u     All unread messages.

       :d     All deleted messages (for the undelete command).

       :r     All read messages.

       :f     All âflaggedâ messages.

       :a     All answered messages (cf. the markanswered variable).

       :t     All messages marked as draft.

       :k     All âkilledâ messages.

       :j     All messages classified as junk.
	.      The current message.

       ;      The message that was previously the current message.

       ,      The parent message of the current message, that is  the  message
              with  the  Message-ID  given  in the âIn-Reply-To:â field or the
              last entry of the âReferences:â field of the current message.

       -      The next  previous  undeleted  message,  or  the  next  previous
              deleted  message  for  the undelete command.  In sorted/threaded
              mode, the next previous  such  message  in  the  sorted/threaded
              order.

       +      The  next undeleted message, or the next deleted message for the
              undelete command.  In sorted/threaded mode, the next  such  mes-
              sage in the sorted/threaded order.

       ^      The  first  undeleted  message, or the first deleted message for
              the undelete command.  In sorted/threaded mode, the  first  such
              message in the sorted/threaded order.

       $      The  last message.  In sorted/threaded mode, the last message in
              the sorted/threaded order.

       &x     In threaded mode, selects the message addressed with x, where  x
              is  any  other  message specification, and all messages from the
              thread that begins at it.  Otherwise, it is identical to x.   If
              x  is  omitted, the thread beginning with the current message is
              selected.

       *      All messages.

       â      All messages that were included in the message list for the pre-
              vious command.
		
		
		
		-- is this what you are saying
		 MIME types
       For any outgoing attachment, mailx tries to determine the content type.  It does this by  reading  MIME  type  files
       whose lines have the following syntax:

               type/subtype      extension [extension . . .]

       where  type/subtype are strings describing the file contents, and extension is the part of a filename starting after
       the last dot.  Any line not immediately beginning with an ASCII alphabetical character  is  ignored  by  mailx.   If
       there  is  a  match with the extension of the file to attach, the given type/subtype pair is used.  Otherwise, or if
       the filename has no extension, the content types text/plain or application/octet-stream are used, the first for text
       or  international  text  files,  the second for any file that contains formatting characters other than newlines and
       horizontal tabulators.
	   
	   Character sets
       Mailx normally detects the character set of the terminal using the LC_CTYPE locale setting.  If the locale cannot be
       used  appropriately,  the  ttycharset  variable  should be set to provide an explicit value.  When reading messages,
       their text is converted to the terminal  character  set  if  possible.   Unprintable  characters  and  illegal  byte
       sequences are detected and replaced by Unicode substitute characters or question marks unless the print-all-chars is
       set at initialization time.

       The character set for outgoing messages is not necessarily the same as the one used on the terminal.  If an outgoing
       text message contains characters not representable in US-ASCII, the character set being used must be declared within
       its header.  Permissible values can be declared using the sendcharsets variable, separated by  commas;  mailx  tries
       each  of  the values in order and uses the first appropriate one.  If the message contains characters that cannot be
       represented in any of the given character sets, the message will not be sent, and its text  will  be  saved  to  the
       âdead.letterâ file.  Messages that contain NUL bytes are not converted.

       Outgoing  attachments  are  converted  if  they are plain text.  If the sendcharsets variable contains more than one
       character set name, the ~@ tilde escape will ask for the character sets for individual attachments if it is  invoked
       without arguments.

       Best  results  are usually achieved when mailx is run in a UTF-8 locale on a UTF-8 capable terminal.  In this setup,
       characters from various countries can be displayed, while it is still possible to use more simple character sets for
       sending to retain maximum compatibility with older mail clients.

i don't know what to do T_T
# 4  
Old 04-19-2016
So - looks like you're lucky. Not all versions of mailx do have the -a option.
# 5  
Old 04-19-2016
what i want sir is to extract/get/save the mail attachment. i think the -a option is to attach the file if you are trying to email.

Please advise,
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Problems sending an attached file with uuencode

I use uuencode in UNIX to send an attached .txt file to my e-mail. The .txt file looks like this: field_1;field_2;field_3 1;2;3 4;5;6 7;8;9 ... When the mail comes, with the attached file, it looks likt thuis: field_1;field_2;field_3 ;1;2;3 ;4;5;6 ;7;8;9 The different lines are... (3 Replies)
Discussion started by: katled
3 Replies

2. UNIX for Dummies Questions & Answers

Removing attached doc from an email

How would you approach a problem of removing an attached document from an email? Later I would parse that attachment and put the data into a database. Can do that part. Unfortunately, I'm not use to the various mail programs - have been looking at sendmail and postfix but haven't... (1 Reply)
Discussion started by: TJ_Green
1 Replies

3. Shell Programming and Scripting

Awk: from two file create a mail with attached error

Hi. My name is Mirko I have two file. File 1: mio@mio.it tst@test.com bye@bye.fr File 2: error 08 ffff mio@mio.it test error 05 ffff bye@bye.fr test error 11 ffff tst@test.com test error 65 ffff mio@mio.it test error 55 ffff bye@bye.fr test Examples I would like to send a mail... (2 Replies)
Discussion started by: Gionfalco01
2 Replies

4. Shell Programming and Scripting

Attached HTML page to Email

Greeting all, Not sure anyone tested to send out email with HTML page as attachment from Shell Script ? I know if I use uuencode file.html approach, the mail receive in attachment is empty. So I guess uuencode cannot be use for the html code. Appreciate if anyone can share the code to... (0 Replies)
Discussion started by: ckwan
0 Replies

5. Shell Programming and Scripting

Script Send Mail by Parameters avec Attached file

Hi i have a script for show the information files. ls -l how do you for to place this result in a file of text and to send it attached for e-mail. The information of the mail must be in paramentros. for example e-mail to I must write the e-mail, the subject and the motive of the mail! ... (1 Reply)
Discussion started by: krlos07
1 Replies

6. Shell Programming and Scripting

Change the font of the attached file while using sendmail

Hi, I have one file which needs to be mailed through sendmail. I am using the following command to send this file to end users. But before sending how can I change the font of the input file to "Courier New" as the mail content was not in proper format if it is any other font. printf... (1 Reply)
Discussion started by: Kattoor
1 Replies

7. Shell Programming and Scripting

Referring to attached images in html email body through mailx

encoding type for images? (5 Replies)
Discussion started by: biswasbaishali
5 Replies

8. UNIX for Dummies Questions & Answers

how to read the first and last column of the attached file

Dear All, I need a small script which will read from a txt file the first and and second and the last clumn of the file and determine how many are having +000 ,+024,+048 error codes. Please help me as soon as possible. Rgrds, A.Ali (2 Replies)
Discussion started by: samura
2 Replies

9. UNIX for Dummies Questions & Answers

To send a mail with a file attached

Hi, Can anyone please tell me how to send a mail to a person in unix with a file attached. The file need to be zipped and then i want to send the mail to a person. I know that we can able to send mail from unix using the command mail mailaddress to send a mail to a person with the... (5 Replies)
Discussion started by: samudha
5 Replies

10. Shell Programming and Scripting

how attached date when renaming log file

I want to rename a log file every weekend but also want to add date in the end of logfile name. How can i do that? Thanks (2 Replies)
Discussion started by: ukadmin
2 Replies
Login or Register to Ask a Question