Pages: 1 2 [3]   Go Down
Author Topic: Email attachments from arduino as an SMTP client  (Read 8977 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Jr. Member
**
Karma: 0
Posts: 67
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

okay i figured that out too, here's a post Incase someone is wondering.
Sending Multiple Attachments

Code:
    Serial.println("connected");
  
                        client.println("HELO itismeletschat"); /* say hello (statement after helo is needed but irrelevant)*/
                          delay(wait); /* wait for a response */

                        client.println("MAIL From: blank@gmx.com"); /* identify sender, this should be the same as the smtp server you are using */
                          delay(wait); /* wait for a response */

                        client.println("RCPT To: blank@virelec.com"); /* identify recipient */
                          delay(wait); /* wait for a response */

                        client.println("DATA");
                          delay(wait); /* wait for a response */
                        
                        client.println("Subject: text file attached");
                        
                        [b]client.print("Content-type: multipart/mixed; boundary=\"$boundary\" \r\n");[/b]
                        
                        [b]client.print("--$boundary\r\n");[/b]
                        
                        datatxt =SD.open("HEAD2.csv",FILE_READ);                
                        client.print("Content-Type: csv; name=\"HEAD2.csv\"\r\nContent-Disposition: attachment; filename=\"HEAD2.csv\"\r\nContent-Transfer-Encoding: base64\r\n\r\n");
                        encode();
                        datatxt.close();
                        delay(wait);
                        
                        datatxt =SD.open("meow.txt",FILE_READ);
                        [b]client.print("--$boundary\r\n");[/b]
                        client.print("Content-Type: txt; name=\"meow.txt\"\r\nContent-Disposition: attachment; filename=\"meow.txt\"\r\nContent-Transfer-Encoding: base64\r\n\r\n");
                        encode();
                        datatxt.close();
                        
                        client.println("."); /* end email */
                        client.println("QUIT"); /* terminate connection */
                        delay(wait); /* wait for a response */
            
           
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 654
Posts: 50931
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
delay(wait); /* wait for a response */
If you are waiting for a response, shouldn't you then read the response? Or else remove the incorrect comment. Even better, remove the useless delay() calls.
Logged

Seattle, WA
Offline Offline
Newbie
*
Karma: 0
Posts: 36
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
delay(wait); /* wait for a response */
If you are waiting for a response, shouldn't you then read the response? Or else remove the incorrect comment. Even better, remove the useless delay() calls.

Some [older] SMTP servers don't support pipelining (i.e. receiving a new command before the current command is responded to), and even for servers that support pipelining, some commands are in herently not pipelineable, so sending commands in quick succession without a bit of delay might be problematic (especially if the sketch is not handling server errors. It might be safer to keep some sort of delay.

Not reading the server response should not be a big deal and the receive buffer should just fill up with unread responses. Downside is of course it can't process server errors. I'm not sure how the Serial stack on the Arduino handles full buffers but if it follows general parctice it will just silently drop the new bytes.

I think the safer way (if reliability is an issue), is to replace the constant wait with a function call that loops to wait for client.available() > 0, and just read and discard the bytes beefore sending the next command. This ensures the server had responded, and to account for transient network delays that causes replies to come back more than the constant wait period.

I realized that I might be getting off topic here ...
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 654
Posts: 50931
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I realized that I might be getting off topic here ...
No, I think you are properly discussing the actions that need to be performed, instead of just blindly waiting what might be just enough time, not near enough time, or way too long.
Logged

Pages: 1 2 [3]   Go Up
Jump to: