error sending email: 554 5.6.0 Message contains invalid header

Hello, I have a little problem sending an email with this program (see attached code)

I use a mega Arduino with a W5100 Ethernet shield

/*
 * EMailSender library for Arduino, Arduino SAMD boards (WiFiNINA), esp8266 and esp32
 * Simple Arduino SAMD boards (WiFiNINA) Gmail send attachments
 * to a single email 
 *
 * https://www.mischianti.org/category/my-libraries/emailsender-send-email-with-attachments/
 *
 */
 
#include "Arduino.h"
#include <EMailSender.h>
#include <SD.h>
#include <SPI.h>
#include <Ethernet.h> 

#define DEFAULT_EMAIL_NETWORK_TYPE_ARDUINO   NETWORK_W5100

Sd2Card card;


byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0x81, 0xB2 };


uint16_t SMTP_PORT = 25;

const char* smtp_server = "smtp.orange.fr";
const char* email_login = "xyz.abc@wanadoo.fr";
const char* email_from = "xyz.abc@wanadoo.fr";
const char* name_from = "Gilles";
const char* email_password = "password";



EMailSender emailSend(email_login,email_password,email_from,name_from,smtp_server,SMTP_PORT);


IPAddress ip(192,168,1,143);  
#define  pinCS_SD  4                                 
#define  pinCS_ETH  10 

 
void setup()
{
    Serial.begin(115200);
 
pinMode(53, OUTPUT);     // pin 53 on Mega
  
   Ethernet.init(pinCS_ETH);                   
   
   char erreur = 0;
Serial.println(F("Initialisation en cours"));

  erreur = Ethernet.begin(mac);

  if (erreur == 0) {
    Serial.println(F("Parametrage avec ip fixe..."));     
    Ethernet.begin(mac, ip);                            
    Serial.println(Ethernet.localIP());                 
    
                  }   //fin du if erreur
                  
  Serial.println(F("Init..."));
 
  delay(1000);                                     
  Serial.println(Ethernet.localIP());
  




    EMailSender::EMailMessage message;   
    message.mime ="text/csv";     
    message.subject = "Envoi fichier relevé mensuel";
    message.message = "Veuillez trouver ci-joint le fichier CSV de la ruche n°1";

    EMailSender::FileDescriptior fileDescriptor[1];   


    fileDescriptor[0].filename = F("FEVR2021.CSV");
    fileDescriptor[0].url = F("/FEVR2021.CSV");
    fileDescriptor[0].mime = "text/csv";
    fileDescriptor[0].encode64 = false;
    fileDescriptor[0].storageType = EMailSender::EMAIL_STORAGE_TYPE_SD;

    EMailSender::Attachments attachs = {1, fileDescriptor};  



   const char* arrayOfEmail[] = {"abc.xy@gmail.com", "xx.yy@wanadoo.fr"};
   
    EMailSender::Response resp = emailSend.send(arrayOfEmail, 2, message, attachs);

 
    
    Serial.print(F("Statut de l'envoi : "));

    Serial.println(resp.status);
    Serial.print(F("Code: "));
    Serial.println(resp.code);
    Serial.print(F("Description : "));
    Serial.println(resp.desc);
}
 
void loop()
{

}

This program works well with the address @ gmail.com but when sending to the address @ wanadoo.fr (or @ orange.fr) I have this message:

This is the mail system at host mwinf5d66.orange.fr.
I’m sorry to have to inform you that your message could not
be delivered to one or more recipients.

The mail system

xx.yy@wanadoo.fr: host back1g-mail01-01.me-wanadoo.net[10.232.119.68] said: 554
5.6.0 Message contains invalid header

And the recipient xx.yy@wanadoo.fr does not receive any email!
While the recipient abc.xy@gmail.com does receive the mail with the attached file!
The error message is delivered to the sender’s mailbox: xyz.abc@wanadoo.fr
The program and the library are from:
EMailSender (Send EMail with attachments) – Renzo Mischianti

Thanks any help will be welcome!

Orange might enforce DKIM (DomainKeys Identified Mail).

Do you know if that header is sent?

Can you see the full header of the mail that has been constructed? may be there is a structure mistake

To my knowledge orange does not yet use the DKIM for the moment (project planned for 2021 …)

Here is the flow of sending the email from the serial monitor:

17:58:27.521 -> Init...
17:58:28.535 -> 192.168.1.33
17:58:28.535 -> multiple recipients and attached files
17:58:28.535 -> Insecure client:0
17:58:28.705 -> 220 mwinf5d66 ME ESMTP server ready

17:58:28.705 -> HELO mischianti: 
17:58:28.739 -> 250 mwinf5d66 hello [90.101.67.75], pleased to meet you

17:58:28.739 -> AUTH LOGIN:
17:58:28.807 -> 334 VXNlcm5hbWU6

17:58:28.807 -> Encoding
17:58:28.807 -> xyz.abc@wanadoo.fr
17:58:28.807 -> 32
17:58:28.807 -> eHl6LmFiY0B3YW5hZG9vLmZy
17:58:28.807 -> Encoding
17:58:28.807 -> xyz.abc@wanadoo.fr
17:58:28.807 -> 32
17:58:28.874 -> 334 UGFzc3dvcmQ6

17:58:28.874 -> Encoding
17:58:28.874 -> password
17:58:28.874 -> 9
17:58:28.874 -> cGFzc3dvcmQ=
17:58:28.874 -> Encoding
17:58:28.874 -> password
17:58:28.874 -> 9
17:58:28.975 -> 235 2.7.0 ... authentication succeeded

17:58:28.975 -> MAIL DE: <xyz.abc@wanadoo.fr>
17:58:29.042 -> 250 2.1.0 <xyz.abc@wanadoo.fr> sender ok

17:58:29.042 -> RCPT TO: <abc.xy@gmail.com>
17:58:29.110 -> 250 2.1.5 <abc.xy@gmail.com> recipient ok

17:58:29.110 -> RCPT TO: <xx.yy@wanadoo.fr>
17:58:29.178 -> 250 2.1.5 <xx.yy@wanadoo.fr> recipient ok

17:58:29.178 -> DATA:
17:58:29.246 -> 354 enter mail, end with "." on a line by itself

17:58:29.280 -> Array: FEVR2021.CSV
17:58:29.313 -> SD Check
17:58:29.514 -> Open file: 
17:58:29.514 -> OK
17:58:29.514 -> NORMAL
17:58:32.189 -> SD end
17:58:32.189 -> SD end 2
17:58:32.189 -> Message end
17:58:32.359 -> 250 2.0.0 SgyU2400L1dRsEJ03gyUnu mail accepted for delivery

17:58:32.393 -> 221 2.0.0 mwinf5d66 ME closing connection

17:58:32.393 -> Statut de l'envoi : 1
17:58:32.393 -> Code: 0
17:58:32.393 -> Description : Message sent!

the library containing all the email headers, and allowing this program to work, is located at this address:

Thank You
PS: I am not at all a programming specialist and I am just starting out … Excuse me

That’s not the exact header being sent.

Clearly orange complains about an invalid header. I suppose it’s the same structure when sent to gmail, so as this works there you should extract it and double check if it fully matches the spec.

Yes it is indeed it is also the conclusion to which I arrived, it seems that the messages sent to Orange want a return line between the header and the body of the message.

I tried to modify the library to add a line return in the EmailMessage structure in the Emailsender.h library.

By modifying like this:

typedef struct {
String mime = "text / html";
String subject;
String line; // add be me
String message;
} EMailMessage;

then by putting in the sketch either line = "\ r \ n"; or line = "U + 0A"; and some other line return code ...

But without success! :frowning:

I have just managed to contact the creator (Italian) of this library, he must look at the origin of the problem, in the meantime I continue to search on my side with all possible help.

Thanks again for your help! :slight_smile:

Headers require their data to be on the same line - double check for unwanted CR or CR/LF in the way the headers are formatted

You can find online headers analyzer tools such as https://mha.azurewebsites.net/ (there are others - this one is the first Google hit)

here is the header of the email that reaches me (gmail) since the one on orange is not received …
For me it’s rather obscure it’s another new area to discover
Summary
Subject: Envoi fichier relevé mensuel
Message Id: e52c3512c8d272a2f6a671dee232e234@mwinf5d66.me-wanadoo.net
Creation time: Mon, 08 Feb 2021 10:36:34 -0800 (PST)
From: Gilles xyz.abc@wanadoo.fr
To: abc.xy@gmail.com,xx.yy@wanadoo.fr

Received
Hop: 1
From: mischianti: ([90.101.67.75])
By: mwinf5d66
With: ME
Id: SgyU2400L1dRsEJ03gyUnu
Date: 2/8/2021 5:58:32 PM

Hop: 2
From: out.smtpout.orange.fr (out06.smtpout.orange.fr. [193.252.22.215])
By: mx.google.com
With: ESMTP
Id: u185si19809723pgc.39.2021.02.08.10.36.31
For: abc.xy@gmail.com
Date: 2/8/2021 7:36:34 PM
Delay: 98 minutes 2 seconds
Percent: 99.98300186979432

Hop: 3
By: 2002:a2e:94d6:0:0:0:0:0
With: SMTP
Id: r22csp631612ljh
Date: 2/8/2021 7:36:35 PM
Delay: 1 second
Percent: 0.016998130205677375

Other
Delivered-To: abc.xy@gmail.com
X-Google-Smtp-Source: ABdhPJwvBHIcP+trrP7lngr407JGjyV9x7inT7l0Z2iHjlZPoRWvI/F5rqTslz/zy6UCQ4/k58cq
X-Received: by 2002:a63:7506:: with SMTP id q6mr3077618pgc.28.1612809394842; Mon, 08 Feb 2021 10:36:34 -0800 (PST)
ARC-Seal: i=1;
a=rsa-sha256;
t=1612809394;
cv=none; d=google.com;
s=arc-20160816;
b=hHxuOxB/nXU0Qufs6mfN40iGt2a49LE9B/Z15v0pbZ0PNdbHsoN/7QwGj5QebeXO/9 EGxNe1O5Sm80oWnOJL/vFXBWa3SIozp0wKN4Ap+0eJpYgaGsKAQXCKr8SQi2MHfxZLgM ahXnr+V6ltoM2ekJN3/UZe8WONIrTBFx66m8xz4bexoUUTJCiYlHAw/PyfTgn80d6LFX vyZrGpEFyOwGrZjHyHhl/YvLtNmZI/z6oazLX07FfSUIwMyN9RMRmZnZYTEWA6hlQwir /YmwzSRc2rmGPv0E18EsO9TesYS+TnOm0cCaXM7Ahxo+J3Tv238iW7LABdpltDqF2Scm IbZA==
ARC-Message-Signature: i=1;
a=rsa-sha256;
c=relaxed/relaxed;
d=google.com;
s=arc-20160816;
h=mime-version:subject:to:from:message-id:date;
bh=/3yxSwDW3Y0uRAGYGlWenymn58K1mEyXEvnB3Li/ZpE=; b=gz33KaFimaZvMDXf7ZvxNZiwidHQVRuRtHGttSfsidy+DmlabzLS+pBuUEJ0JP1ZQj W8aJIrL5gKkfgFwAAbrMeTYKgqC0fPbstanCjve0vI26PSERNYLdAP0Z5rhs9AQF8PVc 0nnWsFqH/X+GZeA9Q0/xQaNNQiwWYIg66cN1XCvsPjNx12BJLUFs2Cznq62+c0ZUULUU qX8Y2Bq3+w3szZaTvy4A3ipPlsv6eZ11Gqtn2VMG3dqMmz6o9nERcP/vMV87/GCBjQJT FubwmNd3k2IiLIKR8QNpvfCurlRx2+v/mfbT47KYuHzIDEI2Y5wFG+MQGZglJ9L2Yo9/ NolQ==
ARC-Authentication-Results:
i=1; mx.google.com; spf=neutral (google.com: 193.252.22.215 is neither permitted nor denied by best guess record for domain of xyz.abc@wanadoo.fr) smtp.mailfrom=xyz.abc@wanadoo.fr
Return-Path: xyz.abc@wanadoo.fr
Received-SPF: neutral (google.com: 193.252.22.215 is neither permitted nor denied by best guess record for domain of xyz.abc@wanadoo.fr)
client-ip=193.252.22.215;
Authentication-Results: mx.google.com;
spf=neutral (google.com: 193.252.22.215 is neither permitted nor denied by best guess record for domain of xyz.abc@wanadoo.fr)
smtp.mailfrom=xyz.abc@wanadoo.fr
X-ME-Helo: mischianti:
X-ME-Auth: eHl6LmFiY0B3YW5hZG9vLmZy
X-ME-Date: Mon, 08 Feb 2021 17:58:32 +0100
X-ME-IP: 90.101.67.75
MIME-Version: 1.0
Content-Type: Multipart/mixed; boundary=frontier
X-Antivirus: Avast (VPS 210207-2, 07/02/2021), Inbound message
X-Antivirus-Status: Clean

I don’t know if this will speak to you but to me it remains even more obscure than before!

Ok this header looks fine

Do you have any way to print the header that is sent to orange?

Impossible (well I think) to have the header of the email for Orange since no receipt of it.
Nevertheless it must be the same since the header is made by the same program (to the address of the receiver which differs) at the same time ...

I meant hacking the library (or find out if it has a debug mode you can activate) to also get on the serial console for example what is being sent

Yes I activated the library debug mde this is what allowed me to get the information:
17:58:28.739 → AUTH LOGIN:
17:58:28.807 → 334 VXNlcm5hbWU6

17:58:28.807 → Encoding
17:58:28.807 → xyz.abc@wanadoo.fr
17:58:28.807 → 32
17:58:28.807 → eHl6LmFiY0B3YW5hZG9vLmZy
17:58:28.807 → Encoding
17:58:28.807 → xyz.abc@wanadoo.fr
17:58:28.807 → 32
17:58:28.874 → 334 UGFzc3dvcmQ6

17:58:28.874 → Encoding
17:58:28.874 → password
17:58:28.874 → 9
17:58:28.874 → cGFzc3dvcmQ=
17:58:28.874 → Encoding
17:58:28.874 → password
17:58:28.874 → 9
17:58:28.975 → 235 2.7.0 … authentication succeeded

17:58:28.975 → MAIL DE: xyz.abc@wanadoo.fr
17:58:29.042 → 250 2.1.0 xyz.abc@wanadoo.fr sender ok

17:58:29.042 → RCPT TO: abc.xy@gmail.com
17:58:29.110 → 250 2.1.5 abc.xy@gmail.com recipient ok

17:58:29.110 → RCPT TO: xx.yy@wanadoo.fr
17:58:29.178 → 250 2.1.5 xx.yy@wanadoo.fr recipient ok

17:58:29.178 → DATA:
17:58:29.246 → 354 enter mail, end with “.” on a line by itself

17:58:29.280 → Array: FEVR2021.CSV
17:58:29.313 → SD Check
17:58:29.514 → Open file:
17:58:29.514 → OK
17:58:29.514 → NORMAL
17:58:32.189 → SD end
17:58:32.189 → SD end 2
17:58:32.189 → Message end
17:58:32.359 → 250 2.0.0 SgyU2400L1dRsEJ03gyUnu mail accepted for delivery

17:58:32.393 → 221 2.0.0 mwinf5d66 ME closing connection

17:58:32.393 → Statut de l’envoi : 1
17:58:32.393 → Code: 0
17:58:32.393 → Description : Message sent!

otherwise the report on the serial monitor is much lighter!

Can you post without the colors tags?

I just saw my post actually the site added color codes to me

I had not noticed

I have modify it ...

Sorry

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.