It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming Visual Basic Forum

email/attachment difficulity

Moderator: dafunkymunky

email/attachment difficulity

Postby nawaray on Mon Mar 10, 2008 6:38 am

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 user@----.com 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: Select all

.ResolveName

2-and if i want to send an email withoout an attachment i get attachment not found

Code: Select all

  .Send


3-and how can i send more than one attachment

this is my code:

Code: Select all

Private Sub Form_Load()
'Sign on to the MAPI Session

MAPISession1.SignOn

MAPIMessages1.SessionID = MAPISession1.SessionID

MAPIMessages1.Fetch


End Sub



Code: Select all

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
           If txtAttach.Text <> vbNullString Then
           .AttachmentPathName = txtAttach.Text
          .AttachmentIndex = 1
           .AttachmentPosition = 1
           .AttachmentPathName = txtAttach.Text
           End If         
           .Send
       End With
         
           

       MAPISession1.SignOff

txtFrom.Text = ""

txtTo.Text = ""

txtSubject.Text = ""

txtMessage.Text = ""
txtAttach.Text = ""

End Sub




Code: Select all

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
Code: Select all
nawaray
 
Posts: 2
Joined: Mon Mar 10, 2008 5:26 am

Who is online

Users browsing this forum: No registered users and 4 guests