Hello,
I've created a mail merge application as per he example on your website.
The Word document is loaded in, and the docprovider is set. I then insert images fine using insert>picture and they show up in the document. Everything appears fine form within the program.
When I send the emails however, the pictures don't show up. From within Outlook I get an error that reads:
"the linked image cannot be displayed. The file may have been moved, renamed, or deleted. Verify that the link points to the correct file and location."
I've attached a screenshot of exactly how I'm inserting the image into the document. Below is the code I use when I send the emails. Also noteworthy, I had to change the formatprovider from docx to rtf before sending the emails. If I use the docxformatprovider, the text in the email shows up with a bunch of symbols, improperly formatted.
Here's DocOpened event I use when opening and loading the word doc:
...and then when sending the emails I use this.
Everything shows up fine in the emails except the image.
I've created a mail merge application as per he example on your website.
The Word document is loaded in, and the docprovider is set. I then insert images fine using insert>picture and they show up in the document. Everything appears fine form within the program.
When I send the emails however, the pictures don't show up. From within Outlook I get an error that reads:
"the linked image cannot be displayed. The file may have been moved, renamed, or deleted. Verify that the link points to the correct file and location."
I've attached a screenshot of exactly how I'm inserting the image into the document. Below is the code I use when I send the emails. Also noteworthy, I had to change the formatprovider from docx to rtf before sending the emails. If I use the docxformatprovider, the text in the email shows up with a bunch of symbols, improperly formatted.
Here's DocOpened event I use when opening and loading the word doc:
try{ OpenFileDialog fDialog = (OpenFileDialog)sender; switch (System.IO.Path.GetExtension(fDialog.FileName)) { case ".docx": docProvider = new DocxFormatProvider(); break; case ".rtf": docProvider = new RtfFormatProvider(); break; case ".txt": docProvider = new TxtFormatProvider(); break; case ".html": docProvider = new HtmlFormatProvider(); break; default: break; } using (FileStream fStream = new FileStream(fDialog.FileName, FileMode.OpenOrCreate, FileAccess.ReadWrite)) { rDoc = docProvider.Import(fStream); } rDoc.LayoutMode = DocumentLayoutMode.Paged; emailForm1.Document = rDoc;}...and then when sending the emails I use this.
protected void SubmitEmail(object sender, RoutedEventArgs e){ MailMessage message = new MailMessage(); byte[] emailBytes = null; string bodyText = string.Empty; SmtpClient mailServer = new SmtpClient("mail.pentegra.com"); mailServer.UseDefaultCredentials = true; this.emailForm1.Document.MailMergeDataSource.ItemsSource = mergeFields; //here's where I change the formatprovider from docx to rtf. if I use docx, the email text comes out as a bunch of symbols docProvider = new RtfFormatProvider(); //this is just a datatable with a list of emails that gets iterated through to send the emails. for (int i = 0; i < _dtMerge.Rows.Count; i++) { message = new MailMessage(); foreach (string s in lstAttachments) { message.Attachments.Add(new Attachment(s)); } message.From = _fromAddress; emailForm1.Document.MailMergeDataSource.MoveToIndex(i); emailBytes = docProvider.Export(emailForm1.Document.MailMergeCurrentRecord()); //I convert the byte array into the email body test here. StringBuilder sb = new StringBuilder(); using (StreamReader sReader = new StreamReader(mStream)) { while (!(sReader.EndOfStream)) { sb.Append(sReader.ReadLine() + Environment.NewLine); } } bodyText = sb.ToString(); message.AlternateViews.Add(AlternateView.CreateAlternateViewFromString(bodyText, null, "text/html")); message.To.Clear(); message.To.Add(new MailAddress("x@xx.com")); mailServer.Send(message); }Everything shows up fine in the emails except the image.