Here is a class to do SMTP mail from System.Web.Mail namespace (with attachments):
' Add a reference to System.Web.
Imports System.Web.Mail
Public Class SmtpMailer
Private m_smtpServer As String
Public Sub New(ByVal smtpServer As String)
m_smtpServer = smtpServer
End Sub 'New(server)
Public ReadOnly Property SmtpServer() As String
Get
Return m_smtpServer
End Get
End Property 'SmtpServer
Public Sub Send(ByVal [to] As String, ByVal from As String, _
ByVal subject As String, ByVal body As String, _
ByVal attachments As String)
' Stripped down version.
MyClass.Send([to], from, subject, "", "", body, MailFormat.Text, attachments)
End Sub 'Send
Public Sub Send(ByVal [to] As String, ByVal from As String, _
ByVal subject As String, ByVal cc As String, ByVal bcc As String, _
ByVal body As String, ByVal format As MailFormat, _
ByVal attachments As String)
' Full version.
Dim message As New MailMessage
message.To = [to]
message.From = from
message.Subject = subject
message.Body = body
message.BodyFormat = format
message.Cc = cc
message.Bcc = bcc
If attachments.Length > 0 Then
Me.AddAttachments(message,
End If
SmtpMail.SmtpServer = Me.SmtpServer
SmtpMail.Send(message)
End Sub 'Send
Private Sub AddAttachments(ByVal message As MailMessage, ByVal attachments As String)
' Split the semi-colon separated list into an array of file names,
' and add each attachment to the mail message.
Dim fileNames() As String = attachments.Split(";")
For Each file As String In fileNames
message.Attachments.Add(fi
Next file
End Sub 'AddAttachments
End Class
Sample usage:
Dim server As New SmtpMailer(hostAddress)
server.Send("To", "From", "Subject", "This is the body", "c:\temp\test1.txt;c:\temp
Bob
Main Topics
Browse All Topics





by: emoreauPosted on 2005-12-29 at 12:24:59ID: 15573279
see http://www.systemwebmail.c om/