Hmmm, the only thing I can think of is that \r might not be an allowed character in the SMTP protocol, so instead of \r\n (which is CR-LF, where CR is only relevant for screen display), you can use \n only. Try breaking down the combined lines in the one print() call into separate println() commands and you might be able get more meaningful diagnostics.
Well i just tried that code again,
it decided to work this time, now i just need to send the contents of the txt file, it didn't have any contents.
but i can send a txt file.
okay i figured that out too, here's a post Incase someone is wondering.
Sending Multiple Attachments
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 */
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.
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 ...
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.
This is how I send a text file attachment from my SD card.
client.println("Subject: Arduino email image");
// this is new
client.write("MIME-Version: 1.0\r\n");
client.write("Content-Type: Multipart/mixed; boundary=frontier\r\n\r\n");
client.write("--frontier\r\n");
client.write("Content-Type: text/plain\r\n\r\n");
client.write("This is an inage from my Arduino!\r\n");
client.write("--frontier\r\n");
client.write("Content-Type: text/plain\r\n");
client.write("Content-Disposition: attachment; filename=test.txt\r\n\r\n");
// this is where you would send your file
int clientCount = 0;
File myFile = SD.open("test.txt");
if(myFile) {
while(myFile.available()) {
clientCount = myFile.read(tBuf,64);
client.write((byte*)tBuf,clientCount);
}
myFile.close();
}
else {
Serial.println(F("File open failed"));
}
client.write("--frontier--\r\n");
// end of new
// send a period on a line by itself
client.println(".");
Hey Tim, that works a charm on text messages. However when I tried to send an image the image is sent all smudged up:
The code is used is:
// this is new
client.write("MIME-Version: 1.0\r\n");
client.write("Content-Type: Multipart/mixed; boundary=frontier\r\n\r\n");
client.write("--frontier\r\n");
client.write("Content-Type: image/jpg\r\n\r\n");
client.write("This is an image from my Arduino!\r\n");
client.write("--frontier\r\n");
client.write("Content-Type: image/jpg\r\n");
client.write("Content-Disposition: attachment; filename=picture.jpg\r\n\r\n");
// this is where you would send your file
int clientCount = 0;
// File myFile = SD.open("test.txt");
File myFile = SD.open("picture.jpg");
if(myFile) {
while(myFile.available()) {
clientCount = myFile.read(tBuf,64);
client.write((byte*)tBuf,clientCount);
}
myFile.close();
}
else {
Serial.println(F("File open failed"));
}
client.write("--frontier--\r\n");
// end of new
// send a period on a line by itself
client.println(".");
if(!eRcv()) return 0;
Serial.println(F("Sending QUIT"));
strcpy_P(tBuf,PSTR("QUIT\r\n"));
client.write(tBuf);
if(!eRcv()) return 0;
client.stop();
Serial.println(F("disconnected"));
Thank you for your reply Tim. I did try the base 64 encoding using the code posted by Razorblade but was not successful. However, i did notice that when I did send images using the code you posted .txt files, the resultant files were not the same.
I opened both the original file and the attachment of the same file that i received in my email in a hex editor.
0x0D in the original were replaced by 0x0A in the attachment at various locations.
I have attached both the files.
I think you must base64 encode the image to send it as an email attachment.
I'm using this encode routine from Razorblades post #18 in this thread (thanks...quoted below) and sending an email with attachment successfully, but I'm getting nowhere near the 50kb/30second speed indicated.
Running on a mega2560 with cc3000 wifi board sending a 5k text file is taking 3 minutes to encode.
Has anyone else seen this kind of time to encode?
(from Post #18)
This would be the whole program. Reads picture.jpg from microSD card, sends an e-mail with picture.jpg attachment:
tBuf should be declared as a 64 byte character array. I declare it as a global variable, but it could be declared as local also if you are running short of SRAM.