gotthardp / rabbitmq-email

SMTP Gateway Plugin for RabbitMQ
Mozilla Public License 2.0
180 stars 20 forks source link

How to send email with attachment? #44

Closed softronsts closed 3 years ago

softronsts commented 3 years ago

Hello, I am trying to send html email with an attachment but receiving the email with file content within the body of the email.

It seems ContentType does not accept the boundary details.

var properties = channel.CreateBasicProperties(); properties.Persistent = true; properties.DeliveryMode = 2; properties.ContentType = multipart.ContentType.ToString(); //properties.ContentType = "multipart/related";

text/html or text/plain emails are processed correctly. Issue is only when the attachment is added.

Config currently holds {email_filter, false}

Seeking your expert advise.

Thank you in advance.

regards, Fayeeg

softronsts commented 3 years ago

Adding Content-Type in the Headers resolved the issue.

properties.ContentType = "multipart/mixed"; Dictionary<string, object> headers = new Dictionary<string, object>(); headers.Add("Subject", subject); headers.Add("Date", DateTime.Today.ToString()); headers.Add("Content-Type", mainMultipart.ContentType.MimeType.ToString() + ";boundary=\"" + mainMultipart.ContentType.Boundary + "\""); properties.Headers = headers;