Skip to content

Commit

Permalink
Fix: Add Message-ID header and user headers
Browse files Browse the repository at this point in the history
Added a valid Message-ID header using an GUID and the host.

Other possible headers added by user to `MailMessage.Headers`
collection are processed.

Fixes nilnull#33 issue
  • Loading branch information
carlosbet committed Jul 29, 2022
1 parent 2e015e4 commit 82f9ba3
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions AegisImplictMail/SmtpSocketClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -867,6 +867,17 @@ public void SendMail(AbstractMailMessage message)
_con.GetReply(out response, out code);
if (!ParseData(code, response)) return;
_con.SendCommand("X-Mailer: AIM.MimeMailer");
_con.SendCommand($"Message-ID: <{Guid.NewGuid()}@{_host}>");
Encoding headersEncoding = MailMessage.HeadersEncoding ?? Encoding.UTF8;
if (headersEncoding.Equals(Encoding.ASCII))
foreach (string header in MailMessage.Headers.AllKeys)
_con.SendCommand($"{header}: {MailMessage.Headers[header]}");
else
{
string encodingName = headersEncoding.BodyName.ToLower();
foreach (string header in MailMessage.Headers.AllKeys)
_con.SendCommand($"{header}: =?{encodingName}?B?{Convert.ToBase64String(MailMessage.HeadersEncoding.GetBytes(MailMessage.Headers[header]))}?=");
}
DateTime today = DateTime.UtcNow;
buf.Append(SmtpCommands.Date);
buf.Append(today.ToString("r"));
Expand Down

0 comments on commit 82f9ba3

Please sign in to comment.