Free Support Forum - aspose.com

Word Document not opening in Mail

hi,

I generated one word document using aspose.word and I tried to send the word doc. through mail. The mail attachment document is not opening.

I am using both Windows 2000 server and 2003. In 2000 server. The code is working, but it fails in 2003 server

Explore the sample code below. I am waiting for ur reply

// Put user code to initialize the page here
Words.Document doc = new Words.Document();

// This truly makes the document empty. No sections (not possible in Microsoft Word).
doc.RemoveAllChildren();


// Create a new section node.
// Note that the section has not yet been added to the document,
// but we have to specify the parent document.
Words.Section section = new Words.Section(doc);

// Append the section to the document.
doc.AppendChild(section);

// Lets set some properties for the section.
section.PageSetup.SectionStart = Words.SectionStart.NewPage;
section.PageSetup.PaperSize = Words.PaperSize.Letter;


// The section that we created is empty, lets populate it. The section needs at least the Body node.
Words.Body body = new Words.Body(doc);
section.AppendChild(body);


// The body needs to have at least one paragraph.
// Note that the paragraph has not yet been added to the document,
// but we have to specify the parent document.
// The parent document is needed so the paragraph can correctly work
// with styles and other document-wide information.
Words.Paragraph para = new Words.Paragraph(doc);
body.AppendChild(para);

// We can set some formatting for the paragraph
para.ParagraphFormat.StyleName = "Heading 1";
para.ParagraphFormat.Alignment = Words.ParagraphAlignment.Center;


// So far we have one empty pararagraph in the document.
// The document is valid and can be saved, but lets add some text before saving.
// Create a new run of text and add it to our paragraph.
Words.Run run = new Words.Run(doc);
run.Text = "Sample NewsClips document";
//run.Font.Color = System.Drawing.Color.Red;
para.AppendChild(run);

// Add 2nd Para
Words.Paragraph para2 = new Words.Paragraph(doc);
body.AppendChild(para2);
para2.ParagraphFormat.StyleName = "Normal";
para2.ParagraphFormat.Alignment = Words.ParagraphAlignment.Left;
Words.Run run2 = new Words.Run(doc);
run2.Text = "This sample document will display the NewsClips";
para2.AppendChild(run2);

//Add a table of contents
//Words.Field toc = new Words.Field();

// As a matter of interest, you can retrieve text of the whole document and
// see that \x000c is automatically appended. \x000c is the end of section character.
//Assert.AreEqual("Hello World!\x000c", doc.GetText());

// Save the document.
doc.Save(@"D:\AsposeTest.doc");
doc = null;

MailMessage msg = new MailMessage();
MailAttachment objattach = new MailAttachment(@"D:\AsposeTest.doc");

msg.From = "username@domain.com";
msg.To = "username@domain.com";
msg.Attachments.Add(objattach);
msg.Subject = "Test";
SmtpMail.SmtpServer = "mail.mailserver.com";
SmtpMail.Send(msg);

Aravind M

Please verify that the document generates ok on the application computer.

If it is so, then it is really hard to say why your document attachment does not get through on Windows 2003. Probably it is some OS firewall or antivirus setting. Please check this issue with your local system administrator.

Best regards,

Hi,

If i attach the two files in attachments, i can able open the files from inbox. The following code is working.

MailMessage msg = new MailMessage();
MailAttachment objattach = new MailAttachment(@"D:\AsposeTest.doc");
MailAttachment objattach1 = new MailAttachment(@"D:\AsposeTest.doc");\

msg.From = "username@domain.com";
msg.To = "username@domain.com";
msg.Attachments.Add(objattach);

msg.Attachments.Add(objattach1);
msg.Subject = "Test";
SmtpMail.SmtpServer = "mail.mailserver.com";
SmtpMail.Send(msg);

This problem occurs only with document generated by using aspose.word

Regards,

Aravind M

Aravind M.

Please send us the problem document before and after being e-mailed, so that we could research this issue.

Hi,

The attachments contains documents before and after sending mail. This problem occurs only in 2003 server only. Not in 2000 machine. When i attach same document twice the both document is opening.Check this in ur environment and reply.

Is there any properties to show screentip in bookmarks? By default it showing the bookname only.

Aravind M

From what I can see all 0x00 (nulls) in your document are substituted with 0x20 (spaces) after the document has been e-mailed.

It is clearly not Aspose.Words problem. Looks like mail server encoding configuration issue. Please check this with your local system administrator.