We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Send mail using system.net in c#

hi,
I just save document in memorystream(Without using any path)
After i read content using stream reader
then i attach stream reader to body of the mail
Here code is

//code
MemoryStream mhtmlStream = new MemoryStream();
// from aspose.word
doc.Save(mhtmlStream, SaveFormat.Mhtml); //not using any file path
StreamReader reader = new StreamReader(mhtmlStream, System.Text.Encoding.UTF8, true);
mhtmlStream.Position = 0;
MailMessage mail = new MailMessage();
mail.From = new MailAddress("abc@gmail.com");
mail.Body = reader.ReadToEnd();
mail.IsBodyHtml = true;
SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com", 587);
SmtpServer.Credentials = new System.Net.NetworkCredential("xyz@gmail.com", "123456");
SmtpServer.EnableSsl = true;
SmtpServer.Send(mail);

this is my code... My word document contains single table with data's...
I just convert word to html

then send to the body of the mail
Now plain text only showing instead of table using html text...

how to avoid this...
Pls Help me

Hi Narendran,


Thanks for contacting support.

Can you please share the input DOC file, so that we can test the scenario in our environment. We are sorry for this inconvenience.

Hi,

Thanks for reply
I attached the source code…
Pls rearrange the document file path, sender and receiver email id


Thanks,
Narendran

Hi Narendran,


Thanks for sharing the sample project.

We are working on testing the scenario and will keep you updated with our findings.

Hi Narendran,


Thanks for your inquiry.

I am afraid you simply cannot pass MHTML to it. MailMessage is used to assemble an e-mail from its parts i.e. HTML code, referenced images and so on, while MHTML is in fact an assembled e-mail. What you are trying to do is insert an assembled e-mail into another e-mail. I suspect that MailMessage is not smart enough to re-assemble MTHML into another message.

Please try saving to HTML format instead and specify various options as follows:

...

...

//This is actually i am doing

doc.Save(@"C:\DATA\file.doc");

//Now i am going to send the above table to body of the mail

MemoryStream htmlStream = new MemoryStream();

HtmlSaveOptions opts = new HtmlSaveOptions(SaveFormat.Html);

opts.ExportImagesAsBase64 = true;

opts.ExportFontsAsBase64 = true;

//Store doucment as a html in memorystraeam

doc.Save(htmlStream, opts);

//Here is the problem...

StreamReader reader = new StreamReader(htmlStream, System.Text.Encoding.UTF8, true);

htmlStream.Position = 0;

MailMessage mail = new MailMessage();

mail.From = new MailAddress("xyz@gmail.com");

mail.Body = reader.ReadToEnd();

mail.IsBodyHtml = true;

mail.BodyEncoding = Encoding.UTF8;

mail.To.Add("abcd@gmail.com");

SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com", 587);

SmtpServer.Credentials = new System.Net.NetworkCredential("xyz@gmail.com"," trtr098)(*");

SmtpServer.EnableSsl = true;

SmtpServer.Send(mail);

}

}

}

Hope, this helps.


Best regards,

Thanks for Reply…


The above code works fine

But
In this above code HtmlsaveOptions did not support "opts.ExportFontsAsBase64 = true"
And moreover Images is not visible in body of the mail… That’s the main problem

Pls reply the solution


Thanks
Hi Narendran,

Thanks for your inquiry. To ensure a timely and accurate response, please attach the following resources here for testing:

  • Your input Word document DOCX containing images and text formatted with custom font
  • Font files

As soon as you get these pieces of information ready, we'll start further investigation into your issue and provide you more information. Thanks for your cooperation.

PS: To attach these resources, please zip them and Click 'Reply' button that will bring you to the 'reply page' and there at the bottom you can include any attachments with that post by clicking the 'Add/Update' button.

Best regards,

I Have attached file


Please tell the solution for getting image in gmail

Hi Narendran,


Thanks for sharing the sample files.

We have further investigated the scenario and as per our observations, Aspose.Words for .NET is properly embedding images and fonts inside resultant HTML file. However we are further looking into this scenario on why images are not appearing in email. We will keep you updated with our findings.

Thanks


Waiting for your reply


Narendran

Hi Narendran,

The MHTML output generated by Aspose.Words in this case correctly embeds the information and there doesn’t seem any issue with the output file in this case. We loaded the same MHTML file using Aspose.Email API instead of System.NET and sent it using the API’s SmtpClient. No such issue was observed at the receiver end. Thus, it doesn’t seem to be an issue with Aspose.Words API as the comparative result of Aspose.Email API show. You can also try with Aspose.Email API and let us know your feedback.

Thanks for your reply…

You are welcome and please feel free to write to us if you have any further query in this regard.