1 Attachment(s)
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:
2-and if i want to send an email withoout an attachment i get attachment not found
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
Re: email/attachment difficulity
sorry this is the correct code for the send button:
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
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
Re: email/attachment difficulity
just my 2 cents
I use a different program for emails from vb that requires semi-colons (;) as
as seperators rather than spaces
Re: email/attachment difficulity
Re: email/attachment difficulity
you can loop through the array to put all the attachment names into the textbox, to display, but you can not then use the textbox text to specify the attachments in the email better to just get them again from the commondialog.filename
like
vb Code:
myarray = split(commondialog.filename, vbnullchar)
for i = 1 to ubound(myarray)
.attachmentindex = i -1
.attachmentposition = i -1
.attachmentpathname = myarray(0) & myarray(i)
next
Re: email/attachment difficulity
hi westconn1
thankx , but i tried what you told me about it''s still not working...
did you see my zip file?
can you show me where to change in my application?
Re: email/attachment difficulity
can someone help me please?
Re: email/attachment difficulity
what part of it is not working?
do you get an error, if so where?
if not what is happening that is not correct?
Re: email/attachment difficulity
i can now send more than one attachment , i got it done...
my problem is now that i cannot send to more than one person....
even if i put in the to text box semicolons or commas( example: [email protected];[email protected]) it will not work , when i debug it i get the error at
so how can i send to more than one user?
Re: email/attachment difficulity
looks like you have to add them in same way as the attachments
Quote:
To add a new recipient, set the RecipIndex to a value greater than or equal to the current recipient count while in the compose buffer. The RecipCount property is updated automatically to reflect the implied new number of recipients. For example, if the current RecipCount property has the value 3, setting the RecipIndex property to 4 adds 2 new recipients and increases the RecipCount property to 5.
read the helpfiles
Re: email/attachment difficulity
i added a new text box...
it will send me for to users , but when i click on the send buttons and when the text box are cleared and then i enter another emails i get the error:
Invalid session
Code:
Code:
.ResolveName
i still cannot put the emails in the same text box seperated by commas
this is my code:
Code:
Code:
With MAPIMessages1
.Compose
.MsgSubject = txtSubject.Text
'.RecipDisplayName = txtTo.Text
'.ResolveName
.RecipIndex = 0
.RecipDisplayName = txtTo.Text
.RecipAddress = txtTo.Text
.RecipType = 1
.ResolveName
.RecipIndex = 1
.RecipDisplayName = txtTo1.Text
.RecipAddress = txtTo1.Text
.RecipType = 1
.ResolveName
Re: email/attachment difficulity
you can put all the recipients in a textbox separated by whatever you want, then when adding the recipients, split the textbox text on the separator, and add the recipients from the array
vb Code:
reciparr = split(txtTo.text, ";")
for i = 0 to ubound(reciparr)
.recipindex = i
.recipdisplayname = reciparr(i)
.recipaddress = reciparr(i)
.resolvename
next