Sending Email with image Error: This file cannot be previewed because of the following error: Microsoft office outlook image previewer

Last Reply 11 months ago By chetan

Posted 11 months ago

What is happening is that:

i am sending a mail with attachment(image).

Suppose i am sending mail to abc@expogp.com, vijaya@expogr.com,rahul@expogp.com,xyz@gmail.com.

They are getting the mails but the problem is when they are trying to open the attatched image it hsows the below window:

This file cannot be previewed because of the following error: Microsoft office outlook image previwer.

In gmail account also,the image is not showing when tried to open it.

The strange thing is that for some people it displays the attatched image.

What will be the issue?

screenshots:

https://ibb.co/PZyFJMp

           SmtpClient smtp = new SmtpClient
           {
               Host = myhost, // smtp server address here…
               Port = p,
                
               EnableSsl = false,
               DeliveryMethod = SmtpDeliveryMethod.Network,
               Credentials = new System.Net.NetworkCredential(eid, pw),
                //Timeout = 30000,
           };
 
           string from = ddlemails.SelectedItem.ToString();
           int idno = -1;
           string mssg = txtmsgbody.Text;
           string myString = Server.HtmlDecode(mssg);
           string fromname = txtfrom.Text;
           foreach (string email in emails)
           {
 
               string SendEmail = email;
               idno = idno + 1; 
               try
               { 
                   MailMessage message = new MailMessage(from, SendEmail, txtsubject.Text, myString);
                   message.From = new MailAddress(from, fromname);
                   message.DeliveryNotificationOptions = DeliveryNotificationOptions.OnSuccess;
                   message.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
                   message.Headers.Add("Disposition-Notification-To", from);
                   message.IsBodyHtml = true;
                   if (fuAttach.HasFile)
                   {
                       filename = Path.GetFileName(fuAttach.PostedFile.FileName);
                       fuAttach.SaveAs(Server.MapPath("~/expo_crm/Attachments/" + filename));
                       Attachment data = new Attachment(fuAttach.PostedFile.InputStream, filename);
                       message.Attachments.Add(data);
                   }
                   smtp.Send(message); 
                   object userid = user_ids[idno]; 
                   Int32 uid = Convert.ToInt32(user_ids[idno]);
                   sent_user_ids.Add(uid);
               }
 
               catch (Exception ex)
               { 
                   errorno++;
                   object userid = user_ids[idno];
                   Int32 uid = Convert.ToInt32(user_ids[idno]);
                   Notsent_user_ids.Add(uid);
               }
           }

 

Posted 11 months ago

Hi sir...i got the solution:

            foreach (string email in emails1)
            {
                string MyEmail1 = email;
                idno = idno + 1;
                if (MyEmail1 != "N/A")
                {
                    try
                    {

                        MailMessage message = new MailMessage(from, MyEmail1, txtsubject.Text, myString);
                        message.From = new MailAddress(from, fromname);
                        message.DeliveryNotificationOptions = DeliveryNotificationOptions.OnSuccess;
                        message.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
                        message.Headers.Add("Disposition-Notification-To", from);
                        message.IsBodyHtml = true;
                        if (fuAttach.HasFile)
                        {
                            filename = Path.GetFileName(fuAttach.PostedFile.FileName);
                            fuAttach.SaveAs(Server.MapPath("~/expo_crm/Attachments/" + filename));//added by chetan
                            fuAttach.PostedFile.InputStream.Seek(0, SeekOrigin.Begin); // added seek
                            Attachment data = new Attachment(fuAttach.PostedFile.InputStream, filename);
                            message.Attachments.Add(data);
                        }
                        smtp.Send(message);
                        sent1++;
                    }

I have added this 1 line and it worked. 

 fuAttach.PostedFile.InputStream.Seek(0, SeekOrigin.Begin); // added seek