Blog di Andrea Soldano

"I have a dream ..."
posts - 53, comments - 263, trackbacks - 18

My Links

News








Tag Cloud

Archives

Post Categories

I miei siti

Inoltrare una pagina Web come e-mail ...

Inoltrare una pagina Web come e-mail:

 

Imports System.Net

Imports System.io

Imports System.Web.Mail

Imports System.Text

Imports System.Web

Public Class EmailUtility

   Public Shared Sub SendEmail(ByVal from As String,  ByVal [to] As String, _

ByVal subject As String, ByVal body As String, _

ByVal bodyFormat As MailFormat)

            Dim message As New MailMessage

            message.From = from

            message.To = [to]

            message.Subject = subject

            message.Body = body

            message.BodyFormat = bodyFormat

 

 

            SmtpMail.SmtpServer = System.Configuration.ConfigurationSettings.AppSettings.Item("SmtpServer")

            SmtpMail.Send(message)

            Exit Sub

 

   End Sub

   Shared Sub New()

   End Sub

 

   Shared Sub InviareIlMessaggio()

      SendEmail("Da", “Destinatario”, "Oggetto", readPage(“Pagina da leggere”, _

MailFormat.Html)

   End Sub

 

   Shared Function readPage(ByVal url As String) As String

    Try

      Dim result As String

      Dim objResponse As WebResponse

      Dim objRequest As WebRequest = System.Net.HttpWebRequest.Create(url)

'Si possono anche aggiungere Chiavi,Valori negli headers da leggere nella pagina da inviare     esempio:

            objRequest.Headers.Add("Chiave", “Valore”)

Per legge il valore nella pagina:

            dim valore as string = request.Headers(“Chiave”)

      objResponse = objRequest.GetResponse()

      Dim sr As StreamReader = New StreamReader(objResponse.GetResponseStream())

      result = sr.ReadToEnd()

      sr.Close()

      Return result

    Catch ex As Exception

      Throw ex

    End Try

  End function

End Class

 

Ciao

Print | posted on giovedì 9 dicembre 2004 11:56 |

Comments have been closed on this topic.

Powered by:
Powered By Subtext Powered By ASP.NET