Results 1 to 12 of 12

Thread: email/attachment difficulity

Threaded View

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Apr 2005
    Posts
    150

    email/attachment difficulity

    hi....
    this is my first application for sending emails through visual basic...

    my application works fine but there are few things i need help please..

    1-when i send an email with an attachment to a person the person will recieve attachments of the same document...(for example if i sent 1.doc to [email protected] this user will recieve in his email the attached document 1.doc two time ) i don't want this to happen...
    and if i want to send to more than one user i get this error :
    Invalid seesion, here where i get the error when i debug:

    Code:
     .ResolveName
    2-and if i want to send an email withoout an attachment i get attachment not found

    Code:
      .Send
    3-and how can i send more than one attachment

    this is my code:

    Code:
    Private Sub Form_Load()
    'Sign on to the MAPI Session
    
    MAPISession1.SignOn
    
    MAPIMessages1.SessionID = MAPISession1.SessionID
    
    MAPIMessages1.Fetch
    
    
    End Sub
    Code:
    Private Sub cmdSend_Click()
    'Start by telling the control that we are composing an e-mail
    
    'MAPIMessages1.Compose
    
    'Use whatever is in the Textboxes as the information for our e-mail.
    
    'MAPIMessages1.RecipDisplayName = txtTo.Text
    
    'MAPIMessages1.MsgSubject = txtSubject.Text
    
    'MAPIMessages1.MsgNoteText = txtMessage.Text
    'MAPIMessages1.AttachmentPathName = txtAttach.Text
    
    'MAPIMessages1.ResolveName
    
    'Send the e-mail message to the Recipient
    
    'MAPIMessages1.Send
    ' MAPISession1.SignOn
    
           'Create Message w/Attachments then Send
           With MAPIMessages1
       
               .Compose
               .MsgSubject = txtSubject.Text
    
               .RecipDisplayName = txtTo.Text
               .ResolveName
    
               'The value 2 is passed to the Space() function in the
               'next line because there are two attachments to add.
               'These spaces act as placeholders for the attachments.
               .MsgNoteText = Space(2) & vbCrLf & _
                   "This message was sent from the MSMAPI32.OCX." & vbCrLf & _
                   "This message contains 2 attachments."
    
               'Replace the AttachmentPathName values below as applicable...
               .AttachmentIndex = 0
               .AttachmentPosition = 0
               .AttachmentPathName = txtAttach.Text
              .AttachmentIndex = 1
               .AttachmentPosition = 1
               .AttachmentPathName = txtAttach.Text
    
              
               .Send
           End With
    
           MAPISession1.SignOff
    
    txtFrom.Text = ""
    
    txtTo.Text = ""
    
    txtSubject.Text = ""
    
    txtMessage.Text = ""
    txtAttach.Text = ""
    
    End Sub
    Code:
    Private Sub cmdBrowse_Click()
    
         Dim sFilenames()    As String
        Dim i               As Integer
        
        On Local Error GoTo Err_Cancel
      
        With cmDialog
            .FileName = ""
            .CancelError = True
            .Filter = "All Files (*.*)|*.*|HTML Files (*.htm;*.html;*.shtml)|*.htm;*.html;*.shtml|Images (*.bmp;*.jpg;*.gif)|*.bmp;*.jpg;*.gif"
            .FilterIndex = 1
            .DialogTitle = "Select File Attachment(s)"
            .MaxFileSize = &H7FFF
            .Flags = &H4 Or &H800 Or &H40000 Or &H200 Or &H80000
            .ShowOpen
            ' get the selected name(s)
            sFilenames = Split(.FileName, vbNullChar)
        End With
        
        If UBound(sFilenames) = 0 Then
            If txtAttach.Text = "" Then
                txtAttach.Text = sFilenames(0)
            Else
                txtAttach.Text = txtAttach.Text & ";" & sFilenames(0)
            End If
        ElseIf UBound(sFilenames) > 0 Then
            If Right$(sFilenames(0), 1) <> "\" Then sFilenames(0) = sFilenames(0) & "\"
            For i = 1 To UBound(sFilenames)
                If txtAttach.Text = "" Then
                    txtAttach.Text = sFilenames(0) & sFilenames(i)
                Else
                    txtAttach.Text = txtAttach.Text & ";" & sFilenames(0) & sFilenames(i)
                End If
            Next
        Else
            Exit Sub
        End If
        
    Err_Cancel:
    
    
    End Sub
    hope some one can help me please ...
    thank you very much
    i will attach my application
    Attached Files Attached Files

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