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
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
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
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case. Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
what part of it is not working?
do you get an error, if so where?
if not what is happening that is not correct?
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case. Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
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
looks like you have to add them in same way as the attachments
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
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case. Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
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:
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
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case. Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete