'************************************************************************************************
'Function Name : SendMail(strFile)
'Purpose : To send a mail with an attachment which is passed as input value to this fn
'Input : File to be attached in the mail
'************************************************************************************************
Public Function SendMail(strFile)
On error Resume Next
'Get the Email ID from the user
strEmailID = InputBox ("Please enter your Email ID:")
'Confirm if the Email id is correct
strOption = msgbox ("Your ID :"&strEmailID,3,"Confirm Mail ID")
'Send mail If it is a correct email ID
if strOption = 6 then
Set objMessage = CreateObject("CDO.Message")
objMessage.Subject = "Report"
objMessage.TextBody = "Attached the Report generated on " & date
'Sender & receiver Email IDs
'===========================
objMessage.From = strEmailID
objMessage.To = strEmailID
'Set the Mail configurations
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mail.example.com"
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
' Note : Change XXXXXX with your userid
'======================================
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusername") = strUser
'Note: Give the corp password - used for SMTP server authentication
'===================================================================
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendpassword") = strPassword
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
objMessage.Configuration.Fields.Update
objMessage.Send
if err.number = 0 then
Msgbox "Pulls report is successfully Sent"
else
msgbox "Report is Failed" & vbcrlf& err.description
end if
else
SendMail
end if
End Function
'################## END OF THE SCRIPT ####################################################################################
Monday, November 9, 2009
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment