Convert from Word to html and email to outlook

Hi,
I have a word document which I convert to html (by using ASPOSE.Words) and send email to the recipients. Every thing work fine when the word document don’t have images but when the word document has the images then the email don’t send those images.
Could you show to me a way to send email via outlook which preserve the images?
Give me some samples.
Best,
Tan Quan

Hi,
Please give me a solution with your suite component.
Best,
Tan Quan

Hi
Thanks for your inquiry. You should add embedded images to your mail. You can achieve this using Aspose.Network. For example see the following code.

string imagePath = @"D:\Aleksey\_projects\Aspos.words\Aspos.words\Tests\TestTwo\bin\273_105760_tanquan\images\";
MemoryStream stream = new MemoryStream();
Document doc = new Document(@"273_105760_tanquan\in.doc");
//save html to stream and images to folder
doc.SaveOptions.ExportImagesFolder = imagePath;
doc.Save(stream, SaveFormat.Html);
//get html code from stream
stream.Position = 0;
StreamReader reader = new StreamReader(stream);
string htmlBody = reader.ReadToEnd();
Aspose.Network.Mail.MailMessage msg = new Aspose.Network.Mail.MailMessage("from@mail.ru", "to@gmail.com");
//add embedded images
string[] imageNames = Directory.GetFiles(imagePath);
for (int i = 0; i < imageNames.Length; i++)
{
    htmlBody = htmlBody.Replace(imageNames[i], "cid:" + Path.GetFileNameWithoutExtension(imageNames[i]));
    Aspose.Network.Mail.LinkedResource image = new Aspose.Network.Mail.LinkedResource(imageNames[i], Aspose.Network.Mime.MediaTypeNames.Image.Jpeg);
    image.ContentId = Path.GetFileNameWithoutExtension(imageNames[i]);
    msg.LinkedResources.Add(image);
}
//send mail
msg.HtmlBody = htmlBody;
Aspose.Network.Mail.SmtpClient client = new Aspose.Network.Mail.SmtpClient("smtp.mail.ru", "from@mail.ru", "password");
client.Send(msg);
//remove images
for (int i = 0; i < imageNames.Length; i++)
{
    File.Delete(imageNames[i]);
}

See the following link for more information.
https://docs.aspose.com/email/net/working-with-message-attachments/
I hope that this will help you.
Best regards.

Hi,
I have an error everything the “client.send” functionality is call and the error has no message.
Please take a look of the function below and could you tell me what I do wrong?

Public Shared Sub SendMail(ByVal docContent As Byte(), ByVal imagePath As String, ByVal fromEmail As String, ByVal toEmail As String, ByVal ccEmail As String, ByVal bccEmail As String, ByVal subjectText As String)
Try
Dim licenseDoc As Aspose.Words.License
Dim licenseNetwork As Aspose.Network.License
licenseDoc = New Aspose.Words.License
licenseDoc.SetLicense(imagePath & "\Aspose.Total.lic")
licenseNetwork = New Aspose.Network.License
licenseNetwork.SetLicense(imagePath & "\Aspose.Total.lic")
Dim docDocument As Document
'save html to stream and images to folder
Dim stream As MemoryStream = New MemoryStream()
docDocument = GetDocument(docContent)
docDocument.SaveOptions.ExportImagesFolder = imagePath & "\WordDocs"
docDocument.Save(stream, SaveFormat.Html)
'get html code from stream
stream.Position = 0
Dim reader As StreamReader = New StreamReader(stream)
Dim htmlBody As String = reader.ReadToEnd()
Dim msg As Mail.MailMessage = New Mail.MailMessage(fromEmail, toEmail)
'add embedded images
Dim imageNames As String() = Directory.GetFiles(imagePath)
Dim i As Integer = 0
Dim j As Integer = 0
For i = 0 To (imageNames.Length - 1)
htmlBody = htmlBody.Replace(imageNames(i), "cid:" + Path.GetFileNameWithoutExtension(imageNames(i)))
Dim image As Mail.LinkedResource = New Mail.LinkedResource(imageNames(i), Mime.MediaTypeNames.Image.Jpeg)
image.ContentId = Path.GetFileNameWithoutExtension(imageNames(i))
msg.LinkedResources.Add(image)
Next
'send mail
'msg.To.Add(toEmail)
If ccEmail <> "" Then msg.CC.Add(ccEmail)
If bccEmail <> "" Then msg.Bcc.Add(bccEmail)
msg.HtmlBody = htmlBody
msg.Subject = subjectText
Dim client As Mail.SmtpClient = New Mail.SmtpClient(GetConfigValue("SmtpServer")) ' "Host", "Username", "password")
client.Send(msg)
'remove images
For j = 0 To (imageNames.Length - 1)
File.Delete(imageNames(i))
Next
licenseDoc = Nothing
licenseNetwork = Nothing
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub

Thanks,
Tan Quan

Hi
Thanks for your inquiry. I think that you should ask this question to Aspose.Network team in the corresponding forum.
https://forum.aspose.com/c/email/12
Best regards.

Hi,
When I convert from Word to html?
How do I know how many images contain in the html file?
The application save all the html images to a sample folder, how do I know what image file below to which html file.
Thanks,
Tan Quan

Hi,
When I convert from Word document to html, all the html images (from many html file) are save a the same folder.
How do I know which images belong to which html file?
Could you give to me a sample of code? The sample that you give it to me assume only for 1 user and how about for multiple users that save image to the same folder
Thanks,
Tan Quan

Hi
Thanks for your inquiry. That’s why I created a temporary folder to save images there. When sending is completed I remove all files from temporary folder. In my example temporary folder is:

string imagePath = @"D:\Aleksey\_projects\Aspos.words\Aspos.words\Tests\TestTwo\bin\273_105760_tanquan\images\";

You can create temporary folder where you want.
Best regards.

Hi,
I can’t delete the file after send an email (client.send). I got this error (when calling the File.Delete):

"The process cannot access the file 'D:\htdocs\Intranet\apps\depts\sec\sr2\admin\WordDocs\PKONDURU\Aspose.Words.22d38a08-23d0-49f5-a4a0-e52da1ec52d4.001.png' because it is being used by another process."

How could I make sure client.send is done before I call the file.delete?
Thanks,
Tan Quan

Hi
Thanks for your inquiry. Aspose.Words is used to convert doc to html. And Aspose.Network is used to create and send mail. Please ask this question Aspose.Network team.
Best regards.