Embed C# email

May 1 2011 12:04 AM
I'm trying to make an email and send an embedded picture in the body of the email.

My current code is

[CODE]EmailP.Visible = false;
int senttt = 0;
if (PrintOuts.Count > 0)
{
StreamReader GetPDFLoc = new StreamReader(Application.StartupPath + "\\Sets.txt");
string PDFLoc = GetPDFLoc.ReadToEnd();
GetPDFLoc.Dispose();
GetPDFLoc.Close();
string[] PDFArray = PDFLoc.Split('`');
string PDFLocFound = PDFArray[1];
lblEmailU.Text = PrintOuts[0] + " " + PrintOuts[1] + " " + PrintOuts[2];
for (int Ent = 0; Ent < PrintOuts.Count; Ent++)
{
if (PrintOuts[Ent] != "Done")
{
for (int EntT = 0; EntT <= PrintOuts.Count - 1; EntT++)
{
if (File.Exists(PDFLocFound + "\\" + PrintOuts[EntT] + ".pdf"))
{
MailMessage Send = new MailMessage();
SmtpClient STMP = new SmtpClient("smtp.live.com");

Send.From = new MailAddress("[email protected]");
Send.To.Add("[email protected]");
Send.Subject = "Test Try";
                              
Send.IsBodyHtml = true;
string SigPath = (Application.StartupPath + "\\Signature.jpg");
string Bodyy = "<p>" + txtEmailT.Text + "<p>N<p>";
if (File.Exists(SigPath))
{
Attachment Signature = new Attachment(SigPath);
Send.Attachments.Add(Signature);
Signature.ContentDisposition.Inline = true;
Signature.ContentDisposition.DispositionType = DispositionTypeNames.Inline;
Signature.ContentId = "Sig";
Signature.ContentType.MediaType = "image/jpeg";
Signature.ContentType.Name = Path.GetFileName(SigPath);
lblDeliveryCo.Text = SigPath;
Bodyy = Bodyy + "<p><img src:\"cid:" + Sig.Name + "\">";
}
else
{
Bodyy = Bodyy + "<p>NNN";
}
System.Net.Mail.Attachment attachT = new System.Net.Mail.Attachment(PDFLocFound + "\\" + PrintOuts[EntT] + ".pdf");
Send.Attachments.Add(attachT);
STMP.Port = 587;
STMP.Credentials = new System.Net.NetworkCredential(WORKING EMAIL, WORKING PASSWORD);
STMP.EnableSsl = true;

STMP.Send(Send);
PrintOuts[EntT] = "Done";
lblPhoneU.Text = Bodyy;
senttt = senttt + 1;
Send.Dispose();
}
}
}
}
}[/CODE]

WORKING EMAIL and WORKING PASSWORD are my email and password for testing, I just renamed it so I'm not giving you all my e-mail and password. All of this works until I embed the image into my e-mail. I've also tried a variation of it following the alternateview HTMLview = new alternateview(); logic, and adding the image, then cid: referencing it's contentID the same way I do here. Neither work.

If I don't embed the picture cid load a blank box, but sends the e-mail. If I don't cid the picture, but load up the attach the picture, it gives me an error. I've tried changing the picture, it still gives me an error - the PDF file load up properly, however. Right now, I think I know how to embed the picture on my own, I just need help actually getting it in the e-mail as an inline attachment or regular attachment. I am using hotmail.

Answers (1)