Have a look at the code closely its not a FSO (FileSystemObject) but a object to FileInfo which is part of .Net Class Library and i named the object as FSO just to make it easily understandable ;)
Sending email using .Net Framework 1.1 (Visual Studio 2003), Save it in a Class Module and then make an object to Class and you can use various options to send email using this class
'=========================== CODE START HERE =================================
Imports System.Web.mail
Imports System.IO
Public Class SMTPMailer
Private MyMail As SmtpMail
Private MyMsg As MailMessage
Sub New(ByVal ServerName As String)
MyMail.SmtpServer = ServerName
End Sub
'Name: SendMail
'
'Inputs:
' SenderName
' Receiver
' Subject
' BodyText
' MessageFormat
' Attachments
' AttachmentEncoding
' Priority
'
'Returns: Nothing
'Assumes: Nothing
'
'Purpose: Sending Mail To SMTP Server
Public Sub SendMail(ByVal Sender As String, ByVal Receiver As String, ByVal Subject As String, ByVal BodyText As String)
Public Sub SendMail(ByVal Sender As String, ByVal Receiver As String, ByVal Subject As String, ByVal BodyText As String, ByVal Priority As MailPriority)
Public Sub SendMail(ByVal Sender As String, ByVal Receiver As String, ByVal Subject As String, ByVal BodyText As String, ByVal Attachments As String, ByVal AttachmentEncoding As MailEncoding)
Public Sub SendMail(ByVal Sender As String, ByVal Receiver As String, ByVal Subject As String, ByVal BodyText As String, ByVal MessageFormat As MailFormat, ByVal Attachments As String, ByVal Priority As MailPriority)
Public Sub SendMail(ByVal Sender As String, ByVal Receiver As String, ByVal Subject As String, ByVal BodyText As String, ByVal MessageFormat As MailFormat)
Public Sub SendMail(ByVal Sender As String, ByVal Receiver As String, ByVal Subject As String, ByVal BodyText As String, ByVal MessageFormat As MailFormat, ByVal Priority As MailPriority)
Public Sub SendMail(ByVal Sender As String, ByVal Receiver As String, ByVal Subject As String, ByVal BodyText As String, ByVal MessageFormat As MailFormat, ByVal Attachments As String, ByVal AttachmentEncoding As MailEncoding, ByVal Priority As MailPriority)
Dim nCtr As Long
Dim sFile() As String
Dim FSO As FileInfo
MyMsg = New MailMessage
If Len(Attachments) > 0 Then
sFile = Split(Attachments, ";")
For nCtr = 0 To UBound(sFile)
FSO = New FileInfo(sFile(nCtr))
If FSO.Exists Then MyMsg.Attachments.Add(New MailAttachment(sFile(nCtr), AttachmentEncoding))
FSO = Nothing
Next
End If
With MyMsg
.From = Sender
If InStr(Receiver, ";") > 0 Then
.To = Mid(Receiver, 1, InStr(Receiver, ";") - 1)
.Cc = Mid(Receiver, InStr(Receiver, ";") + 1)
Else
.To = Receiver
End If
.BodyFormat = MessageFormat
.Subject = Subject
.Body = BodyText
.Priority = Priority
End With
MyMail.Send(MyMsg)
MyMsg = Nothing
End Sub
End Class
'================================== CODE END HERE ===================================
Code Request
Karthik R181134
You're right......
Sapient
but it's way out of date... in a way. The FSO is no longer recommended.
Ram Ram
subramaniac
Tola Omicron
Sending email using .Net Framework 1.1 (Visual Studio 2003), Save it in a Class Module and then make an object to Class and you can use various options to send email using this class
'=========================== CODE START HERE =================================
Imports System.Web.mail
Imports System.IO
Public Class SMTPMailer
Private MyMail As SmtpMail
Private MyMsg As MailMessage
Sub New(ByVal ServerName As String)
MyMail.SmtpServer = ServerName
End Sub
'Name: SendMail
'
'Inputs:
' SenderName
' Receiver
' Subject
' BodyText
' MessageFormat
' Attachments
' AttachmentEncoding
' Priority
'
'Returns: Nothing
'Assumes: Nothing
'
'Purpose: Sending Mail To SMTP Server
Public Sub SendMail(ByVal Sender As String, ByVal Receiver As String, ByVal Subject As String, ByVal BodyText As String)
SendMail(Sender, Receiver, Subject, BodyText, MailFormat.Text, "", MailEncoding.Base64, MailPriority.Normal)
End Sub
Public Sub SendMail(ByVal Sender As String, ByVal Receiver As String, ByVal Subject As String, ByVal BodyText As String, ByVal Priority As MailPriority)
SendMail(Sender, Receiver, Subject, BodyText, MailFormat.Text, "", MailEncoding.Base64, Priority)
End Sub
Public Sub SendMail(ByVal Sender As String, ByVal Receiver As String, ByVal Subject As String, ByVal BodyText As String, ByVal Attachments As String)
SendMail(Sender, Receiver, Subject, BodyText, MailFormat.Text, Attachments, MailEncoding.Base64, MailPriority.Normal)
End Sub
Public Sub SendMail(ByVal Sender As String, ByVal Receiver As String, ByVal Subject As String, ByVal BodyText As String, ByVal Attachments As String, ByVal AttachmentEncoding As MailEncoding)
SendMail(Sender, Receiver, Subject, BodyText, MailFormat.Text, Attachments, AttachmentEncoding, MailPriority.Normal)
End Sub
Public Sub SendMail(ByVal Sender As String, ByVal Receiver As String, ByVal Subject As String, ByVal BodyText As String, ByVal MessageFormat As MailFormat, ByVal Attachments As String, ByVal Priority As MailPriority)
SendMail(Sender, Receiver, Subject, BodyText, MessageFormat, Attachments, MailEncoding.Base64, Priority)
End Sub
Public Sub SendMail(ByVal Sender As String, ByVal Receiver As String, ByVal Subject As String, ByVal BodyText As String, ByVal MessageFormat As MailFormat)
SendMail(Sender, Receiver, Subject, BodyText, MessageFormat, "", MailEncoding.Base64, MailPriority.Normal)
End Sub
Public Sub SendMail(ByVal Sender As String, ByVal Receiver As String, ByVal Subject As String, ByVal BodyText As String, ByVal MessageFormat As MailFormat, ByVal Priority As MailPriority)
SendMail(Sender, Receiver, Subject, BodyText, MessageFormat, "", MailEncoding.Base64, Priority)
End Sub
Public Sub SendMail(ByVal Sender As String, ByVal Receiver As String, ByVal Subject As String, ByVal BodyText As String, ByVal MessageFormat As MailFormat, ByVal Attachments As String, ByVal AttachmentEncoding As MailEncoding, ByVal Priority As MailPriority)
Dim nCtr As Long
Dim sFile() As String
Dim FSO As FileInfo
MyMsg = New MailMessage
If Len(Attachments) > 0 Then
sFile = Split(Attachments, ";")
For nCtr = 0 To UBound(sFile)
FSO = New FileInfo(sFile(nCtr))
If FSO.Exists Then MyMsg.Attachments.Add(New MailAttachment(sFile(nCtr), AttachmentEncoding))
FSO = Nothing
Next
End If
With MyMsg
.From = Sender
If InStr(Receiver, ";") > 0 Then
.To = Mid(Receiver, 1, InStr(Receiver, ";") - 1)
.Cc = Mid(Receiver, InStr(Receiver, ";") + 1)
Else
.To = Receiver
End If
.BodyFormat = MessageFormat
.Subject = Subject
.Body = BodyText
.Priority = Priority
End With
MyMail.Send(MyMsg)
MyMsg = Nothing
End Sub
End Class
'================================== CODE END HERE ===================================
woh
Cellardoor76
Wow - no way would it require that much code....