p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Beginning VB 6 (http://p2p.wrox.com/forumdisplay.php?f=75)
-   -   Send an email using MAPI sessions through VB 6.0 (http://p2p.wrox.com/showthread.php?t=80050)

lkumar_esoftsys July 7th, 2010 10:32 AM

Send an email using MAPI sessions through VB 6.0
 
Hi All,
  1. I am trying to send an email using MAPI controls from my VB Application. But while sending email I will get an pop message from Microsoft outlook which says

    “A Program is trying to access e-mail address information
    stored in Outlook. If this is unexpected, click Deny and
    verify your anti virus software is up-to-date.


    For more information about e-mail safety and how you
    might be able to avoid getting this warning, click Help.”


    With a check box “Allow access for” and a combo box that shows the list of minutes from 1, 2, 5 & 10 minutes.

    With 3 buttons saying Allow, Deny & Cancel.
  2. After clicking on the allow button I will get another pop up message from Microsoft outlook which says

    “A Program is trying to access e-mail address information
    stored in Outlook. If this is unexpected, click Deny and
    verify your anti virus software is up-to-date.

    For more information about e-mail safety and how you

    might be able to avoid getting this warning, click Help.”


    With 3 buttons saying Allow, Deny & Cancel.
For each and every email that I send, I need to click on Allow button twice.

Please help me on how to disable this pop up message.

Below is the piece of code which I used to send email using MAPI Controls.

With frmMain
If .objMAPISess.SessionID = 0 Then
.objMAPISess.LogonUI = True
.objMAPISess.SignOn
End If

.objMAPIMess.SessionID = .objMAPISess.SessionID
.objMAPIMess.Compose
.objMAPIMess.AddressResolveUI = True

.objMAPIMess.AttachmentPathName = App.Path & "\Mail\" & p_strFileName & ".pdf"

If (Trim(p_strEmailID) <> "") Then
.objMAPIMess.AddressResolveUI = False
.objMAPIMess.RecipIndex = 0
.objMAPIMess.RecipType = 1
.objMAPIMess.RecipAddress = p_strEmailID
.objMAPIMess.ResolveName

.objMAPIMess.RecipIndex = 1
.objMAPIMess.RecipType = 3
.objMAPIMess.RecipAddress = strFacilityEMail
.objMAPIMess.ResolveName

.objMAPIMess.MsgSubject = p_strSubject
.objMAPIMess.MsgNoteText = p_strMessage
.objMAPIMess.send showDialog:=False 'True
End If
End With

Thanks & Regards
Lakshmi Kumar

vb5prgrmr July 9th, 2010 01:45 AM

EnunWindows, EnumChildWindows, and SendMessage are a few of the API's you will need to use to solve this...



Good Luck

lkumar_esoftsys July 9th, 2010 01:59 AM

Thank you for your help. But I dont know how to use these API's. Please give me some sample coding if you have.

vb5prgrmr July 9th, 2010 09:12 AM

Use your friends (yahoo, google, ask, answers, bing) and search for vb6 api name... like vb6 findwindow to find a ton of examples, if not more than a ton....



Good Luck

john02813 December 24th, 2012 12:34 AM

I use vb 6 with Windows Live to send email
 
'you need to have MAPI as a component on your form.
If MAPISession1.NewSession Then
' check if session is already opened
Else
With MAPISession1 'MAPISession
' Set DownLoadMail to False to prevent immediate download.
.DownLoadMail = False
' Use the underlying email system's logon UI.
' .UserName = "john02813@hotmail.com"
' .Password = "hotrunner12"
' .LogonUI = True
.SignOn
.NewSession = True
MAPIMessages1.SessionID = .SessionID
End With

With MAPIMessages1 'MAPIMessage

' .SessionID = MAPISession1.SessionID
' .Fetch
' For i = 0 To .MsgCount - 1
' .MsgIndex = i
' lst.AddItem .MsgSubject
' lst.ItemData(lst.NewIndex) = i
' Next
.Compose
.RecipDisplayName = "John Alexander"
.RecipAddress = "john02813@hotmail.com"
.AddressResolveUI = True

.MsgSubject = "Just another VB test"
.MsgNoteText = "I am still trying to send you email from VB"
.Send False
.SessionID = MAPISession1.SessionID

End With
MAPISession1.NewSession = False ' Flag for new session.
MAPISession1.SignOff

End If
Me.MousePointer = vbDefault

arindam46 December 11th, 2013 07:40 AM

Sending Mail Using MAPI
 
When i try to send a mail using the below mentioned code an exception occurs on sign on that "Error in loading MAPI DLL". Now when i try add mapi32.dll as a reference by browsing it form c:\Windows\System32\mapi32.dll it cannot be added as a reference showing that it is not a valid COM component. So what should i do to SignOn in the code mentioned below.

Dim mapisession1 As New MSMAPI.MAPISession
Dim MAPIMessages1 As New MSMAPI.MAPIMessages
mapisession1.LogonUI = True
'mapisession1.UserName = "abc@gmail.com"
'mapisession1.Password = "**********"
mapisession1.SignOn()
With MAPIMessages1
.SessionID = mapisession1.SessionID
.Compose()
.MsgSubject = "test"
.RecipIndex = 0
.RecipAddress = "xyz@yahoo.co.in"
.ResolveName()
.MsgNoteText = "Here You go"
'.AttachmentIndex = 0
'.AttachmentPosition = 0
'.AttachmentPathName = strFilePath

.Send()
End With
mapisession1.SignOff()


All times are GMT -4. The time now is 09:24 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.