Results 1 to 3 of 3

Thread: Here we go again with EMAIL

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2002
    Posts
    41

    Angry Here we go again with EMAIL

    Here I sit all broken hearter because of all the time wasted on email with VB6. Can someone PLEASE help me! I found an email program written from someone here. It goes like this:
    Private Sub Command1_Click()
    MAPISession1.SignOn

    With Me.MAPIMessages1

    .SessionID = MAPISession1.SessionID

    .MsgIndex = -1

    .Compose

    .MsgSubject = "Order"

    .RecipType = mapToList

    .RecipDisplayName = "Dan"

    .RecipAddress = "[email protected]"

    ' SHOW THE ADDRESS BOOK WITH THE SELECTED RECIPIENT(S)

    ' 0=NO EDIT FIELDS, 1=TO, 2=(TO AND CC), 3=(TO, CC AND BLIND CC),
    ' 4=ONLY THOSE SUPPORTED BY MESSAGING SYSTEM WILL BE SHOWN

    .AddressEditFieldCount = 1

    .MsgNoteText = "Your order is being sent"

    ' ADD ATTACHMENT FILE IF THE LABEL CONTAINS A SELECTED FILE

    .AttachmentPosition = 0

    .AttachmentName = "dan.txt"

    .AttachmentPathName = "c:\products\dan.txt"

    .AttachmentType = mapEOLE

    ' SEND THE EMAIL

    .Send

    End With

    MAPISession1.SignOff

    End Sub
    The problem is, isn't mapi suppose to use the client's default mail program? Works great if you have outlook express on your computer, but what if you don't? It works up to the point of the attachment and then errors out saying that it can't find the attachment. Please respond.
    Dan

  2. #2
    Frenzied Member
    Join Date
    Jan 2001
    Location
    Newbury, UK
    Posts
    1,878
    What is your default E-mail program?
    Does it handle MAPI commands? (like Outlook and Outlook Express do).
    Or does it only handle Simple MAPI commands?

    If it only handles Simple MAPI, then use the MAPI Session and MAPI Message controls (just drop them on a form, they are not visible at run time), and remove any references to MAPI from your references list.
    VB Code:
    1. MAPISession1.SignOn
    2. With MAPIMessages1
    3.         .SessionID = MAPISession1.SessionID
    4.         .Compose
    5.         .RecipAddress = “a.a&a.com”
    6.         .ResolveName
    7. ‘For a second addressee add:
    8. ‘        .RecipIndex = 1
    9. ‘        .RecipAddress = "[email protected]"
    10. ‘        .ResolveName
    11. ‘ Might need to add:
    12. ‘        .AddressResolveUI = True
    13.  
    14.         .MsgSubject = "My Subject"
    15.         .MsgNoteText = "My body"
    16.         .AttachmentIndex = 0
    17.         .AttachmentPosition = 0
    18.         .AttachmentPathName = "c:\temp\test.txt"
    19.  ‘For a secnd attachment add:
    20.  ‘       .AttachmentIndex = 1
    21.  ‘       .AttachmentPosition = 1
    22.  ‘       .AttachmentPathName = "c:\temp\x01.txt"
    23.         .Send
    24. End With
    25. MAPISession1.SignOff

  3. #3
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    Well

    VB Code:
    1. '*******************************************************************************
    2. ' SENDMESSAGETHRUOUTLOOK (SUB)
    3. '
    4. ' DESCRIPTION:
    5. ' ACTUALLY SEND THE EMAIL MESSAGE THRU OUTLOOK
    6. '*******************************************************************************
    7.  
    8. Sub SENDMESSAGETHRUOUTLOOK(DisplayMsg As Boolean, Optional AttachmentPath)
    9.    
    10.     Dim objOutlook As Outlook.Application
    11.     Dim objOutlookMsg As Outlook.MailItem
    12.     Dim objOutlookRecip As Outlook.Recipient
    13.     Dim objOutlookAttach As Outlook.Attachment
    14.    
    15.     ' CREATE THE OUTLOOK SESSION.
    16.    
    17.     Set objOutlook = CreateObject("Outlook.Application")
    18.    
    19.     ' CREATE THE MESSAGE.
    20.    
    21.     Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
    22.    
    23.     With objOutlookMsg
    24.        
    25.         ' ADD THE TO RECIPIENT(S) TO THE MESSAGE.
    26.        
    27.         Set objOutlookRecip = .Recipients.Add(Me.txtAddressTO.Text)
    28.        
    29.         objOutlookRecip.Type = olTo
    30.        
    31.         ' SET THE SUBJECT, BODY, AND IMPORTANCE OF THE MESSAGE.
    32.        
    33.         .Subject = Me.txtSubject.Text
    34.        
    35.         .HTMLBody = Me.txtMsg.Text
    36.        
    37.         .Importance = olImportanceHigh  ' HIGH IMPORTANCE
    38.        
    39.         ' ADD ATTACHMENTS TO THE MESSAGE.
    40.        
    41.         If Not IsMissing(AttachmentPath) Then
    42.            
    43.             Set objOutlookAttach = .Attachments.Add(Me.lblAttachment.Caption)
    44.            
    45.         End If
    46.        
    47.         ' RESOLVE EACH RECIPIENT'S NAME.
    48.        
    49.         For Each objOutlookRecip In .Recipients
    50.            
    51.             objOutlookRecip.Resolve
    52.            
    53.         Next
    54.        
    55.         ' SHOULD WE DISPLAY THE MESSAGE BEFORE SENDING?
    56.        
    57.         If DisplayMsg Then
    58.            
    59.             .Display
    60.            
    61.         Else
    62.            
    63.             .Save
    64.            
    65.             .Send
    66.            
    67.         End If
    68.        
    69.     End With
    70.    
    71.     Set objOutlook = Nothing
    72.    
    73. End Sub
    74.  
    75.  
    76.  
    77. '*******************************************************************************
    78. ' SENDMESSAGETHRUEXPRESS (SUB)
    79. '
    80. ' DESCRIPTION:
    81. ' ACTUALLY SEND THE EMAIL MESSAGE THRU EXPRESS
    82. '*******************************************************************************
    83.  
    84. Sub SENDMESSAGETHRUEXPRESS(DisplayMsg As Boolean, Optional AttachmentPath)
    85.    
    86.     MAPISession1.SignOn
    87.    
    88.     With Me.MAPIMessages1
    89.        
    90.         .SessionID = MAPISession1.SessionID
    91.        
    92.         .MsgIndex = -1
    93.        
    94.         .Compose
    95.        
    96.         .MsgSubject = Me.txtSubject
    97.        
    98.         .RecipType = mapToList
    99.        
    100.         .RecipDisplayName = Me.txtAddressTO
    101.        
    102.         .RecipAddress = Me.txtAddressTO
    103.        
    104.         ' SHOW THE ADDRESS BOOK WITH THE SELECTED RECIPIENT(S)
    105.        
    106.         ' 0=NO EDIT FIELDS, 1=TO, 2=(TO AND CC), 3=(TO, CC AND BLIND CC),
    107.         ' 4=ONLY THOSE SUPPORTED BY MESSAGING SYSTEM WILL BE SHOWN
    108.        
    109.         .AddressEditFieldCount = 1
    110.        
    111.         .MsgNoteText = Me.txtMsg
    112.        
    113.         ' ADD ATTACHMENT FILE IF THE LABEL CONTAINS A SELECTED FILE
    114.        
    115.         If Len(Me.lblAttachment.Caption) > 0 And Me.lblAttachment.Caption > " " Then
    116.            
    117.             .AttachmentPosition = 0
    118.            
    119.             .AttachmentName = lblAttachment
    120.            
    121.             .AttachmentPathName = lblAttachment
    122.            
    123.             .AttachmentType = mapEOLE
    124.            
    125.         End If
    126.        
    127.         ' SEND THE EMAIL
    128.        
    129.         .Send
    130.        
    131.     End With
    132.    
    133.     MAPISession1.SignOff
    134.    
    135. End Sub

    The MAPI / Express example requires the MAPI controls...

    Outlook you must reference the Outlook Library...

    or yet another way... http://216.26.168.92/vbsquare/internet/sendmail-demo/
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width