Dear Sir,
I tried the above tutorial. I follwed all the steps exactly as explained. I came across following two problems.
- If the mail is sent it is going without attachment.
- It is not sent at all saying “SPIFFS Upload failed!”
Please guide me.
Regards
D. V. Apte
Baroda – India
Hi.
What is the code that you’re using?
What attachment are you trying to send?
Regards,
Sara
Did you place the attachments on a folder called data inside the project folder?
Did you upload the data folder to the ESP32 as shown in this picture?
Regards,
Sara
Yes Madam,
I am following all the steps exactly as explained in the tutorial. the problem is
- Some times If the mail is sent it is going without attachment.
- But some times It is not sent at all saying “SPIFFS Upload failed!”
And by the way I appreciate your prompt responses to my questions. Thank you very much for the same.
Regards
D. V. Apte
Baroda – India.
Hi.
I’ve just tested the example and it is working fine.
Are you using gmail accounts?
Does your account allow receiving attachments?
If SPIFFS upload fails, double-check that you don’t have any instance of the serial monitor opened. Additionally, depending on your board, you may need to press the BOOT button when you start seeing a lot of dots in the debugging window.
Regards,
Sara
Dear Madam,
Thanks for your response. I am using “Gmail account” only. I am pressing pressing “Boot” button while up loading the sketch.
Only thing I will have to now check if any other instance of Serial Monitor is opened. I will once again do this tutorial with above instruction and will revert back to you.
Once again Thank you very much for your prompt response and excellent support.
Regards
D. V. Apte
Baroda – India
Dear Madam,
I Tried again with folloing sketch. But the mail and the attachments are not going at all
”
/*
Rui Santos
Complete project details at https://RandomNerdTutorials.com/esp32-send-email-smtp-server-arduino-ide/
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files.
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
*/
#include “ESP32_MailClient.h”
#include “SD.h”
#include “SPIFFS.h”
// REPLACE WITH YOUR NETWORK CREDENTIALS
const char* ssid = “REPLACE_WITH_YOUR_SSID”;
const char* password = “REPLACE_WITH_YOUR_PASSWORD”;
// To send Email using Gmail use port 465 (SSL) and SMTP Server smtp.gmail.com
// YOU MUST ENABLE less secure app option https://myaccount.google.com/lesssecureapps?pli=1
#define emailSenderAccount “”
#define emailSenderPassword “”
#define emailRecipient “”
#define smtpServer “smtp.gmail.com”
#define smtpServerPort 465
#define emailSubject “From D V APTE – 5 – ESP32 Test Email with Attachments”
// The Email Sending data object contains config and data to send
SMTPData smtpData;
// Callback function to get the Email sending status
void sendCallback(SendStatus info);
void setup(){
Serial.begin(115200);
Serial.println();
// Initialize SPIFFS
if(!SPIFFS.begin(true)) {
Serial.println(“An Error has occurred while mounting SPIFFS”);
return;
}
// Or initialize SD Card (comment the preceding SPIFFS begin)
/*
MailClient.sdBegin(14, 2, 15, 13); // (SCK, MISO, MOSI, SS)
if(!SD.begin()){
Serial.println(“Card Mount Failed”);
return “”;
}*/
Serial.print(“Connecting”);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
Serial.print(“.”);
delay(200);
}
Serial.println();
Serial.println(“WiFi connected.”);
Serial.println();
Serial.println(“Preparing to send email”);
Serial.println();
// Set the SMTP Server Email host, port, account and password
smtpData.setLogin(smtpServer, smtpServerPort, emailSenderAccount, emailSenderPassword);
// For library version 1.2.0 and later which STARTTLS protocol was supported,the STARTTLS will be
// enabled automatically when port 587 was used, or enable it manually using setSTARTTLS function.
smtpData.setSTARTTLS(true);
// Set the sender name and Email
smtpData.setSender(“ESP32”, emailSenderAccount);
// Set Email priority or importance High, Normal, Low or 1 to 5 (1 is highest)
smtpData.setPriority(“High”);
// Set the subject
smtpData.setSubject(emailSubject);
// Set the message with HTML format
smtpData.setMessage(“<div style=\”color:#2f4468;\”><h1>Hello World!</h1><p>- Sent from ESP32 board</p></div>”, true);
// Set the email message in text format (raw)
//smtpData.setMessage(“Hello World! – Sent from ESP32 board”, false);
// Add recipients, you can add more than one recipient
smtpData.addRecipient(emailRecipient);
//smtpData.addRecipient(“YOUR_RECIPIENT_EMAIL_ADDRESS@example.com”);
// Add attach files from SD card or SPIFFS
// Comment the next two lines, if no SPIFFS files created or SD card connected
smtpData.addAttachFile(“/ESP32-CAM-Test.jpg”, “image/jpg”);
smtpData.addAttachFile(“/text_file.txt”);
// Add some custom header to message
// See https://tools.ietf.org/html/rfc822
// These header fields can be read from raw or source of message when it received)
//smtpData.addCustomMessageHeader(“Date: Sat, 10 Aug 2019 21:39:56 -0700 (PDT)”);
// Be careful when set Message-ID, it should be unique, otherwise message will not store
//smtpData.addCustomMessageHeader(“Message-ID: <abcde.fghij@gmail.com>”);
// Set the storage type to attach files in your email (SPIFFS or SD Card)
smtpData.setFileStorageType(MailClientStorageType::SPIFFS);
//smtpData.setFileStorageType(MailClientStorageType::SD);
smtpData.setSendCallback(sendCallback);
//Start sending Email, can be set callback function to track the status
if (!MailClient.sendMail(smtpData))
Serial.println(“Error sending Email, ” + MailClient.smtpErrorReason());
//Clear all data from Email object to free memory
smtpData.empty();
}
void loop() {
}
// Callback function to get the Email sending status
void sendCallback(SendStatus msg) {
// Print the current status
Serial.println(msg.info());
// Do something when complete
if (msg.success()) {
Serial.println(“—————-“);
}
}
“
Hi again.
I’m sorry, but it is very difficult to find out what might be wrong.
I’ve used that same sketch, but with my credentials and it worked perfectly.
Do you get any errors on the debugging window or in the serial monitor?
Did you allow less secure apps in the sender email account? https://myaccount.google.com/lesssecureapps?pli=1
I don’t know what else might be wrong.
Regards,
Sara