Receiving specific email directly using VBA

m_solaiman

New member
Local time
Today, 14:31
Joined
Jun 24, 2010
Messages
1
Hi:
I have this code to send an Email via ms access directly.(see the attach code)
Could I have a such code to receive a specific Email?
For example I have a message with the name "NewMessage1" in my gmail inbox.
Can I download it directly via access?
please
Function fnSendEMail(tbGmailLogin As String, tbTo As String, tbPassword As String)
MsgBox " Êã ÍÝÙ ÇáÓÌá", vbExclamation
On Error GoTo fnSendEMail_Err
'original code by westconn1

Set objMessage = CreateObject("CDO.Message")
objMessage.Subject = "This is some sample message text."
objMessage.From = tbGmailLogin
'objmessage.To = Me.tbTo & "@stc.com.sa"
objMessage.To = tbTo
objMessage.TextBody = "This is some sample message text."
objMessage.AddAttachment "c:\EMail_temp\tblBills.txt" ' --> change it for the path of your file(attachment)

objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2

'Name or IP of Remote SMTP Server

'Type of authentication, NONE, Basic (Base64 encoded), NTLM
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
'Your UserID on the SMTP server
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusername") = tbGmailLogin

'Your password on the SMTP server

objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendpassword") = tbPassword
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
'Server port (typically 25)
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
'Use SSL for the connection (False or True)
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
'Connection Timeout in seconds (the maximum time CDO will try to establish a connection to the SMTP server)
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 30
objMessage.Configuration.Fields.Update
objMessage.Send
Set objMessage = Nothing

'Call MsgBox("E-mail sent via Gmail SMTP", vbInformation, Application.Name)

fnSendEMail_Exit:
Exit Function

fnSendEMail_Err:
MsgBox Error$
Resume fnSendEMail_Exit

End Function
 

Users who are viewing this thread

Back
Top Bottom