HTML attachment through ASP.NET

Results 1 to 2 of 2

Thread: HTML attachment through ASP.NET

  1. #1
    Join Date
    Dec 1969

    Default HTML attachment through ASP.NET

    i have a webform that generates a report.I want to send the report to an email address as an attachment.The contents of the report are avaliable through an object.<BR><BR>I way would be invoking Word at the server and writing a file and sending it.But i believe that is too much load and is not advised to install word on the server.<BR>How can i make an html document or if i have the html code for the page , send it as an html page attachment.Since the report has a few images too.<BR><BR>I am using ASP.NET and VB.NET<BR><BR>Please help.

  2. #2
    Join Date
    Dec 1969

    Default RE: HTML attachment through ASP.NET

    You have a couple of options here.<BR>1. You can actually place HTML (Rich Text) within your Email if you wish. This may be better than sending an attached HTML. Provided the recipient can access and accept HTML emails (otherwise if will be displayed all jumbled with the tags in the text) this is pretty straight forward.<BR><BR>HOW TO:<BR>a. make sure you have Imports System.Web.Mail<BR>b. access the email:<BR> Dim oMailMessage As MailMessage<BR><BR> oMailMessage = New MailMessage<BR> oMailMessage.From = sUserRequester & ""<BR> oMailMessage.To = sUserRequester & ";"<BR> oMailMessage.Subject = "Test Email"<BR> oMailMessage.Body = "&#060;HTML&#062;&#060;HEAD&#062;&#060;BODY&#0 62; &#060;a href=&#039;; target=&#039;_blank&#039;&#062;Click me for proof&#060;/a&#062;"<BR> oMailMessage.BodyFormat = MailFormat.Html<BR><BR> SmtpMail.SmtpServer = "xxxxx"<BR> SmtpMail.Send(oMailMessage)<BR>c. you can specify as many recipients as you wish, as well as lists, provided they are on your system.<BR>d. You MUST (as far as I know) specify your SMTP server.<BR><BR>2. For creating and attaching a file. Simply open a new file, write to it, and then, using the above email code, you can specify an attachment.<BR><BR>HOW TO:<BR>a. I believe you have to have: Imports System.IO<BR>b. specify the code as follows:<BR> dim oWriter as StreamWriter<BR> oWriter = File.CreateText(MapPath("myFile.txt"))<BR> oWriter.WriteLine(&#060;specify your file content here&#062;)<BR> oWriter.Close<BR>**Note, you can specify your file as any extension, i.e. txt, htm, asp, etc. That way, you can input whatever code you wish. You can make a string of html tags and information and save it as a .htm file, then attach it to your email ... all dynamically.<BR><BR>Hope this helps,<BR><BR>D

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts