EMailSender and SendGrid

Viewing 6 reply threads
  • Author
    Posts
    • #30104
      Jules
      Participant

        To send an e-mail with EMAilSender, you can work with SendGrid. (https://sendgrid.com/en-us)
        – create an account (free up to 100 mails per day).
        install an application on the mobile phone for 2-level authentication
        – create a SMTP Relay API key (full access)
        copy the key and all your account information.

        at the beginning of the code, don’t forget to enter :
        —————————————————
        #include <Arduino.h>
        #include <SPI.h>
        #include <Ethernet.h>
        #include <EMailSender.h>
        #define DEFAULT_EMAIL_NETWORK_TYPE_ARDUINO NETWORK_W5100 //If you’re using a schield W5100.
        byte mac[6] = { 0x** 0x**, 0x**, 0x**, 0x**, 0x** }; // Your Adress Mac
        IPAddress ip(192, 168, *, ***); // Your Address IP

        EMailSender emailSend(“apikey”, “your_password_apikey”, “your_mail”, “smtp.sendgrid.net”, 587 );

        // apikey signals that we’re going to send a code related to an api module
        // your_password_apikey is the password given by Sendgrid when requesting an SMTP Relay key.
        // your_mail is the Sendgrid login address.
        // You must use 587 as port

        void setup()
        {
        // Open serial communications and wait for port to open:
        Serial.begin(115200);
        // while (!Serial) {}
        delay(2000);

        Serial.println(“Port série ok”);

        // start the Ethernet connection:
        pinMode(4, OUTPUT); // config for shield W5100 on MEGA2560
        digitalWrite(4, HIGH); // config for shield W5100 on MEGA2560
        if (Ethernet.begin(mac) == 0) {
        Serial.println(“Failed to configure Ethernet using DHCP”);
        while(1);
        }
        Serial.print(“Addresse IP “);
        Serial.println(Ethernet.localIP());

        EMailSender::EMailMessage message;
        message.subject = “Test”;
        message.message = “This indicates a reboot of the arduino”;
        EMailSender::Response resp = emailSend.send(“address@****.***”, message);
        Serial.print(“Status: “);
        Serial.println(resp.desc);

        void loop()
        {
        if(Serial.read() == ‘S’) {
        if(sendEmail_1()); // to send the mail
        }
        }

        byte sendEmail_1() {
        EMailSender::EMailMessage message;
        message.subject = “Your mail title”;
        message.message = “Your information message”;
        EMailSender::Response resp = emailSend.send(“address@****.***”, message);
        Serial.print(“status: “);
        Serial.println(resp.desc);
        }
        ——————————————————————
        Just incorporate this sketch into your own and have fun!

        I had to search a lot of forums to find a simple way to send email alerts from my Arduino system. (I have information coming from my heater, a pump, etc …).
        The EMailSender and SendGrid combination is the simplest.

      • #30105
        Renzo Mischianti
        Keymaster

          Thanks Jules,
          Your info will be precious for a lie of people.
          Bye Renzo

        • #30257
          erjon
          Participant

            Hey I tried your Code but could you tell me more detailed how did you set up the SendGrid because i think i have everything good exept that.

            thanks

          • #30259
            Jules
            Participant

              You need to create a SendGrid account and take the free option.
              You will need a confirmation app on your mobile phone.
              then create an api (relay).
              Save your codes, they won’t be visible after they’ve been created.
              that should do it.
              see : https://sendgrid.com/en-us/blog/smtp-relay-service-basics

              • This reply was modified 1 year, 8 months ago by Jules.
              • #30306
                erjon
                Participant

                  Hello,

                  Could we go on a Call about this. I dont quite understand the part of the confirmation app on the phone.

                  Bye

              • #30307
                Jules
                Participant

                  it’s a simple 2-level confirmation …
                  (mail + password) and mobile number
                  Sorry, but I don’t think we can call each other. I live in Belgium and I don’t understand enough English to hold a conversation. Writing is one thing, but conversation is another…

                • #30308
                  erjon
                  Participant

                    So Actually i did everything as told and my code is the same as yours i did 2FA on the sendgrid and i confirmed my mobile number too.
                    – I also did a Sender Authentication From where to where it needs to go // is this necessecary?
                    – I used the SMPT Relay where i made an api key and i used it for the apikey and apikey passowrd // is this correct?
                    – When i send a mail through arduino the Intnernet is working because i can see that it makes TCP connection to Sendgrid servers.
                    – Im sending from an Outlook Email to a Gmail Email and i dont know if that is right.

                    -do you need to pay sendgrid at anypoint because i want to use it for my self and send some email time to time ?

                    Hee i will put my Code (i want it to keep it very simple) maybe you can see any mistakes 🙂

                    
                    #include <Ethernet.h>
                    //#define DEFAULT_EMAIL_NETWORK_TYPE_ARDUINO   NETWORK_W5100
                    #include <Arduino.h>
                    #include <SPI.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 };
                     
                    EMailSender emailSend("apikey", "apikey-psw", "<my sendgrid email>", "smtp.sendgrid.net", 587);
                     
                    void setup()
                    {
                        // Open serial communications and wait for port to open:
                        Serial.begin(9600);
                    //    while (!Serial) {}
                     
                        Serial.println("Starting!");
                     
                        // 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 = "This is a Test";
                        message.message = "Its a Test";
                     
                        EMailSender::Response resp = emailSend.send("the email i want the maessage to go", message);
                     
                        Serial.println("Sending status: ");
                     
                        Serial.println(resp.status);
                        Serial.println(resp.code);
                        Serial.println(resp.desc);
                    }
                     
                    void loop()
                    {
                        Serial.begin(9600);
                        Serial.println("Starting!");
                    }
                    

                    Thank you because im trying for a Week to get this working 🙂

                    • This reply was modified 1 year, 7 months ago by erjon.
                  • #30319
                    Jules
                    Participant

                      //#define DEFAULT_EMAIL_NETWORK_TYPE_ARDUINO NETWORK_W5100 <== deleting the // , the line must be made active

                      EMailSender emailSend(“apikey”, “apikey-psw”, “<my sendgrid email>”, “smtp.sendgrid.net”, 587);

                      // apikey remains apikey
                      // apikey-psw is the key given by SendGrid (64 characters)
                      // snedgridmail ==> do not put the < >

                      // ERROR : EMailSender::Response resp = emailSend.send(“the email i want the maessage to go”, message);
                      ok => EMailSender::Response resp = emailSend.send(“recipient@mail.***”, message);

                      make these changes and it should work
                      SendGrid is normally free for non-intensive personal use
                      since you didn’t put a destination address, it couldn’t go … “recipient@mail.***”

                  Viewing 6 reply threads
                  • You must be logged in to reply to this topic.
                  Exit mobile version