Hello, I'm desperately trying to send mail from my Arduino Mega via an Ethernet shield.
To start, I unsuccessfully tried the example provided in the library, here is the code:
I can't send an email even without an attachment ...
I have a doubt about what to put in the function:
EMailSender emailSend (email_login, email_password, email_from, smtp_server, smtp_port);
I put this kind of information (is it in base 64 as in another example or in ASCII or ...) Thank you
/*
* EMailSender library for Arduino, esp8266 and esp32
* Arduino Mega and UIPEthernet send example with attach
* this example is not tested for all, I can't find a provider
* that manage attach without SSL and TLS
*
* Pay attention you must set in the library
* #define DEFAULT_EMAIL_NETWORK_TYPE_ARDUINO NETWORK_ENC28J60
* for UIPEthernet
*
* #define DEFAULT_EMAIL_NETWORK_TYPE_ARDUINO NETWORK_W5100
* for standard Ethernet
* https://www.mischianti.org/category/my-libraries/emailsender-send-email-with-attachments/
*
*/
#include "Arduino.h"
#include <SPI.h>
#include <UIPEthernet.h>
#include <SD.h>
#include <EMailSender.h>
// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
const char* email_login= "rtl21.gin@wanadoo.fr"; or base 64?
const char* email_password= "RZy28tb"; or base 64?
const char* email_from="rde.mduin@wanadoo.fr";
const char* smtp_server="smtp.orange.fr";
uint16_t smtp_port =25;
EMailSender emailSend (email_login, email_password, email_from, smtp_server, smtp_port);
Sd2Card card;
#define pinCS_SD 4
#define pinCS_ETH 10
void printDirectory(File dir, int numTabs);
//The setup function is called once at startup of the sketch
void setup()
{
Serial.begin(115200);
pinMode(53, OUTPUT); //Arduino mega
delay(2000);
Serial.println("Starting!");
Serial.print("Initializing SD card...");
if (!card.init(SPI_HALF_SPEED, pinCS_SD)) {
Serial.println("initialization failed!");
return;
} else [Serial.println("initialization done.");}
Ethernet.init(pinCS_ETH);
File root = SD.open("/");
printDirectory(root, 0);
Serial.println("done!");
// start the Ethernet connection:
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
while(1);
}
Serial.print("IP address ");
Serial.println(Ethernet.localIP());
EMailSender::EMailMessage message;
message.subject = "Soggetto";
message.message = "Ciao come stai
io bene.
www.mischianti.org";
message.mime = MIME_TEXT_PLAIN;
// One file
EMailSender::FileDescriptior fileDescriptor[1];
fileDescriptor[0].filename = F("test.txt");
fileDescriptor[0].url = F("/test.txt");
fileDescriptor[0].mime = MIME_TEXT_PLAIN;
fileDescriptor[0].storageType = EMailSender::EMAIL_STORAGE_TYPE_SD;
EMailSender::Attachments attachs = {1, fileDescriptor};
EMailSender::Response resp = emailSend.send("email_to_receive@gmail.com", message, attachs);
Serial.println("Sending status: ");
Serial.println(resp.status);
Serial.println(resp.code);
Serial.println(resp.desc);
File root2 = SD.open("/");
printDirectory(root2, 0);
Serial.println("done!");
SD.end();
}
void loop()
{
}
void printDirectory(File dir, int numTabs) {
while (true) {
File entry = dir.openNextFile();
if (! entry) {
// no more files
break;
}
for (uint8_t i = 0; i < numTabs; i++) {
Serial.print('\t');
}
Serial.print(entry.name());
if (entry.isDirectory()) {
Serial.println("/");
printDirectory(entry, numTabs + 1);
} else {
// files have sizes, directories do not
Serial.print("\t\t");
Serial.println(entry.size(), DEC);
}
entry.close();
}
}
And in addition when compiling this example I get warning messages (even if it compiles and the program runs ... bad but runs anyway)
see next post for alert codes (no more space in the 1st)
Thanks a lot for any help!