VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Sending Email to multiple recipients using MAPI

by Sergei Lossev (2 Submissions)
Category: Miscellaneous
Compatability: Visual Basic 3.0
Difficulty: Unknown Difficulty
Date Added: Wed 3rd February 2021
Rating: (9 Votes)

It seems that a lot of people are having problems sending Email from VB to multiple people. Here's a procedure that should fix that.

Inputs
EmailAddress is of the form "[email protected];[email protected]" and etc. Subject and MessageText are self explainatory.
Assumes
You are gonna need a form with the two MAPI controls, named like in the code. The rest you should be able to get by yourself.
Code Returns
Nothing
Side Effects
Should work. It does on my computer :o)

Rate Sending Email to multiple recipients using MAPI

Public Sub SendEmail(sEmailAddress As String,sSubject as string, sMessageText as string)
  Dim sEmailExtracted As String
  Dim sEmailLeft As String
  Dim iRecipCount As Integer
  
  If Trim(sEmailAddress) = "" Then
      Goto SendMail_End
  End If
  
  sEmailLeft = Trim(sEmailAddress)
  
  ' set the mouse pointer to indicate the app is busy
  Screen.MousePointer = vbHourglass
  
  MAPIlogon.SignOn
    
  Do While MAPIlogon.SessionID = 0
  
  
    DoEvents ' need to wait until the new session is created
    
  Loop
  
    With MAPIMessages1
      .MsgIndex = -1
      .SessionID = MAPIlogon.SessionID
      
      While sEmailLeft <> ""
      
        If InStr(1, sEmailLeft, ";") = 0 Then
          sEmailExtracted = sEmailLeft
          sEmailLeft = ""
        Else
          sEmailExtracted = Left(sEmailLeft, InStr(1, sEmailLeft, ";") - 1)
          sEmailLeft = Right(sEmailLeft, Len(sEmailLeft) - InStr(1, sEmailLeft, ";"))
        End If
      
        .RecipIndex = iRecipCount
        If iRecipCount = 0 Then
          .RecipType = mapToList
        Else
          .RecipType = mapCcList
        End If
        
        .RecipAddress = sEmailExtracted
        
        .ResolveName
        
        iRecipCount = iRecipCount + 1
        
      Wend
  
      If iRecipCount = 0 Then GoTo SendMail_End
      
      .MsgSubject = sSubject
      .MsgNoteText = sMessageText      
      .Send
    End With
    
    MAPIlogon.SignOff
SendMail_End:  
  Screen.MousePointer = vbNormal
  Exit Sub
End Sub

Download this snippet    Add to My Saved Code

Sending Email to multiple recipients using MAPI Comments

No comments have been posted about Sending Email to multiple recipients using MAPI. Why not be the first to post a comment about Sending Email to multiple recipients using MAPI.

Post your comment

Subject:
Message:
0/1000 characters