CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

How to create an attachment file to a GPRS Email?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Tagge



Joined: 23 Aug 2005
Posts: 93

View user's profile Send private message Visit poster's website

How to create an attachment file to a GPRS Email?
PostPosted: Sat Jul 11, 2009 7:19 pm     Reply with quote

Hi, I would like to create an attachment to an GPRS Email, because the module, Telit, demands it if the data is larger than 1kb.
How could it be done? or can it be done? I suppose any kind of "file" will do as long it contents ascii chars? It would be nice if its an .txt mode and therefore been able to be opened with for ex notepad.
The "file" has of course to be made "on the fly" due to lack of memory in the PIC, a 10kb buffer isn't nice.
Or as my data is stored in an 2M flash ic on the board, maybe it can be saved in some "file" format? its also updated(added to) once an hour.
Anyway it has to be able to be referred to as an attachment file when sending the data.
Code:

AT#EMAILD=<da>,
<subj>,<att>
[,<filename>]

My data is about 10k bytes.
I'm using PIC18F97J60 and an Telit module.
Any ideas?
thanks, tagge
bkamen



Joined: 07 Jan 2004
Posts: 1611
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Sun Jul 12, 2009 2:48 pm     Reply with quote

This is really the wrong forum for this -- as you are asking "how do I construct an email message".

You should be reading http://www.ietf.org/rfc/rfc2821.txt

and then making sure to review your mime types.

I do this stuff in scripting languages under Unix all the time. It's pretty easy -- if you do the reading.

Cheers,

-Ben
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
Tagge



Joined: 23 Aug 2005
Posts: 93

View user's profile Send private message Visit poster's website

PostPosted: Tue Jul 14, 2009 12:50 pm     Reply with quote

Hi, no, the problem is not to create an e-mail, that is done "automatically" in the Telit module by AT commands. The problem is to make an ascii buffer that is recognized as an file? and therefore be able to be attached.
But I'm afraid it can be impossible.. so maybe I just have to be satisfied with the 1Kb of data that can be in the body, that at least works fine.
And admit that a 8-bit PIC isn't the right mcu to use in this sort of applications.
Maybe instead some sort of an linux kernel and a 32 bit mcu with a fat memory.
But thanks any way
/Tagge
bkamen



Joined: 07 Jan 2004
Posts: 1611
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Tue Jul 14, 2009 1:52 pm     Reply with quote

are you trying to send binary data in the attachment that needs to be base64 encoded or just plain text?

If so, the mime headers for the email are easy... if the telit stuff doesn't do it up early (needs to be in the headers) then it's a problem.

So a > 1kb text attachment or straight binary (if supported upstream) is easy.

base64 encoding, not so nice on a PIC if large files are intended.

-Ben
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
Tagge



Joined: 23 Aug 2005
Posts: 93

View user's profile Send private message Visit poster's website

PostPosted: Wed Jul 15, 2009 3:39 am     Reply with quote

Hi, thanks,
Yes, I just want to send ascii chars as an textfile and as an attachement.
My problem is how to define a string or a buffer as a .txt file?
or .bin or any file.
/Tagge
Guest








PostPosted: Wed Jul 15, 2009 5:55 am     Reply with quote

Hi

As I see it, it's not possible, you must have some kind of file system and you don't. If the Telit expect a plain text file to read from the Pearl I can't see how you want to handle this from a clean ram layout...?
bkamen



Joined: 07 Jan 2004
Posts: 1611
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Wed Jul 15, 2009 8:43 am     Reply with quote

I don't know the delivery mechanism to telit, but in my TCL scripts, you declare the mime header and then just STDOUT all the stuff you want and then end it with the appropriate separator.

I'll supply some TCL code that acts as a document mailer. It's pretty easy to read... but it's not C. So I apologize. (it's also written for Sendmail in Unix) However, I think you'll still get the idea.. Sendmail can take an email in multiple methods. File, STDIN. One just has to construct it properly. (and maybe this is still even missing a few things. I wrote this about 8 years ago.)

Anyway - I hope it helps. You want only the stuff between my "look here" markers.

However change the
puts $ofh "--$boundary"
to
puts $ofh "--$boundary--" (See the 2 -'s on the end? they signify the end of the markers/mime attachments. IMPORTANT! :D

And $boundary can be anything as long as it's unique in the email. So make it a 40col mixed hex number. (could even be the same from one message to another. AS LONG AS IT'S UNIQUE IN IT'S OWN MESSAGE.)

I'm rambling. Sorry.


Code:

<====Look from here =====>
            set timestamp [ clock seconds ]
            set hextimestamp [ format "%X" $timestamp ]
            set boundary "--$hextimestamp$hextimestamp$hextimestamp"

            set ofh [open "|/usr/sbin/sendmail -t " w ]
            puts $ofh "From: Ben (WebScript) <someemail@yourdomain.net>"
            puts $ofh "X-Mailer: Ben's Web DocMailer version 1.0 (tcl; U; AIX 4.3)"
            puts $ofh "MIME-Version: 1.0"
            puts $ofh "To: $FormData(email)"
            puts $ofh "Subject: Here's the file you requested, $FormData(file)"
            puts $ofh "Content-Type: multipart/mixed; boundary=\"$boundary\""
            puts $ofh ""
            puts $ofh "This is a multi-part message in MIME format."
            puts $ofh "--$boundary"
            puts $ofh "Content-Type: text/plain; charset=us-ascii"
            puts $ofh "Content-Transfer-Encoding: 7bit"
            puts $ofh ""
            puts $ofh " This message was sent automatically per your request"
            puts $ofh " via the DocMailer system from my web site."
            puts $ofh ""
            puts $ofh " Need anything else? Email me at myemail@somedomain.net or"
            puts $ofh " click back to http://www.benjammin.net"
            puts $ofh ""
            puts $ofh " - Ben"
            puts $ofh ""
            puts $ofh "--$boundary"

<====Look to here =====>

            if { [ regexp {[.](.*)$} $FormData(file) ] } {
               set ext "[file extension $FormData(file)]"
               if { ! [ catch { open "$defaults(mimefile)" "r" } fh ] } {
                  while { [gets $fh mimedef] >=0 } {
                     regexp {^AddType[\t\s]+([.]\w+)[\t\s]+(.*/.*)[\t\s]+(\w+)[\t\s]+.*$} $mimedef junk fileExt mimeType encoding
                     if { [ regexp -- $ext $fileExt ] } {
                        break
                     }
                  }
               }
            } else {
               if { ! [info exists $fileExt] } {
                  PrintMessage 5
                  exit
               }
            }

            set filesize "[file size "$RootPath/$FormData(file)"]"

            if { ! [ catch { open "$RootPath/$FormData(file)" "r" } fh ] } {
               fconfigure $fh -translation binary
               fconfigure $ofh -translation binary
               set buffer [read $fh]
               if { ! [ regexp "text" $mimeType ] } {
                  set buffer "[::base64::encode -maxlen 100 $buffer]"
                  set encoding "base64"
               }
               close $fh
            } else {
               puts stderr "DOCUMENT_URI = $env(DOCUMENT_URI)"
               puts stderr "fullFileName = $FormData(file)"
               puts stderr "   Could not open file ($fh)"
               puts "Could not open requested file... Sorry - Ask Ben!"
               puts ""
               exit
            }

            puts $ofh "Content-Type: $mimeType; name=\"$FormData(file)\""
            puts $ofh "Content-Transfer-Encoding: $encoding"
            puts $ofh "Content-Disposition: attachment; filename=\"$FormData(file)\"; size=\"${filesize}\""
            puts $ofh "Content-Length: ${filesize}"
            puts $ofh ""
            puts -nonewline $ofh $buffer
            flush $ofh

            fconfigure $ofh -translation crlf
            puts $ofh "--$boundary--"
            puts $ofh "."
            flush $ofh
            close $ofh

_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group