Is there any way in which we can log into our Outlook account throgh VB and send a mail.
Printable View
Is there any way in which we can log into our Outlook account throgh VB and send a mail.
Yes, add a reference to MS Outlook xx.0 Object Library and create an email. I have many many code examples on the forums already. Try a search by my user name and Outlook. ;)
I know how to send a mail through VB but it works only if Outlook is open and any user is logged on. I want to know if we can supply the userID and password through code and execute it. I was using the following code to send the mail
Can anyone help me out.VB Code:
Private Sub Form_Load() Dim app As Outlook.Application Dim mail As Outlook.MailItem Set app = CreateObject("Outlook.Application") Set mail = app.CreateItem(olMailItem) With mail .To = "[email protected]" .Subject = "Hi This is a test mail" .Body = "There is an error" '.Attachments.Add "\\server\drive\folder\filename", olByValue, 1 .Send End With End Sub
You can log on like so...
VB Code:
Option Explicit Private Sub Form_Load() Dim app As Outlook.Application Dim mail As Outlook.MailItem Set app = CreateObject("Outlook.Application") app.GetNamespace("MAPI").Logon "Profile", "Password", "ShowDialog", "New Session" Set mail = app.CreateItem(olMailItem) With mail .To = "[email protected]" .Subject = "Hi This is a test mail" .Body = "There is an error" '.Attachments.Add "\\server\drive\folder\filename", olByValue, 1 .Send End With End Sub