I want to send a password email to a user, however the customer wants an image embedded (inline) in the email.
I created an email, saved the data to a txt file, during my code I read in the template but when I send it the line endings are broken and therefore the MIME data is broken. I just get =3D
What am I doing wrong?
string FILENAME = Server.MapPath("~/GuestUserTemplate.txt");
StreamReader objStreamReader = File.OpenText(FILENAME);
string sEmailTemplate = "";
string input = null;
while ((input = objStreamReader.ReadLine()) != null)
{
sEmailTemplate = sEmailTemplate + input;
}
objStreamReader.Close();
/* send an email */
MailMessage msg = new MailMessage();
msg.IsBodyHtml = true;
msg.To.Add(new MailAddress(sToEmail));
msg.From = new MailAddress(sFromEmail);
msg.Subject = sEmailSubject;
msg.Body = sEmailTemplate;
//try
{
client.Send(msg);
}
//catch (Exception excm)
{
}
Just done a bit more detective work. The email I am sending out has this in the header:
MIME-Version: 1.0
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: quoted-printable
Where as an email which has inline images has:
Content-class: urn:content-classes:message
MIME-Version: 1.0
Content-Type: multipart/related;
boundary="----_=_NextPart_001_01C9C98D.6552117E";
type="multipart/alternative"
It seems that I need to set the Content type to multipart but I am not sure how...