Log inUsernamePassword
Log me on automatically each visit    
Register
Register
Log in to check your private messages
Log in to check your private messages
Visual Basic Forum for Visual Basic Programmers VB Forum Index » Knowledge Base

Post new topic   Reply to topic
Sending Mail with Attachments
View previous topic :: View next topic  
Author Message
Avis
Junior Poster


Joined: 07 Oct 2003
Posts: 510
Location: India

PostPosted: Aug 2nd, 2004 06:47 AM    Post subject: Sending Mail with Attachments Reply with quote

This code lets you send e-mails from your program with attachments. Just copy paste whats below and replace as needed.

[vb:1:6c755e0d24]Dim path_name As String
Private Sub Form_Load()
MAPISession1.SignOn
MAPIMessages1.SessionID = MAPISession1.SessionID
End Sub

Public Sub Command1_Click()

Dim path_x as string

With cd1
InitDir = "C:\"
Filter = "All Files(*.*)|*.*"
ShowOpen
path_x = .FileName
End With

path_name = path_x

End Sub

Public Sub Command2_Click()

Dim find_char, i, x, j As Integer
Dim stratt_name As String

MAPIMessages1.Compose
MAPIMessages1.RecipDisplayName = txtto.Text
MAPIMessages1.MsgSubject = "Sending Mail from VB"
MAPIMessages1.MsgNoteText = "Hope u are feeling me"
MAPIMessages1.AttachmentPathName = path_name

For i = 1 To Len(path_name)

find_char = InStr(i, path_name, "\")
If find_char + 7 > Len(path_name) - 4 Then
GoTo stop_loop
End If
Next i
stop_loop:

x = find_char

stratt_name = Right(path_name, Len(path_name) - x)
MAPIMessages1.AttachmentName = stratt_name
MAPIMessages1.ResolveName
j = MsgBox("One message sent to : " & txtto & " with an attachment : " & stratt_name, vbInformation, "Message Sent")
'Send the mail message to the Recipient with an attachment
MAPIMessages1.Send
End Sub

Private Sub Form_Unload(Cancel As Integer)
MAPISession1.SignOff
Unload Me
End Sub[/vb:1:6c755e0d24]
_________________
Code Snippets, Tutorials, Utilities, Controls

Low cost Web Hosting
Hosting starts at as low as $4 per year!


Always follow posting guidelines
Put your VB code in [vb ] your code [ /vb] tags!
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger ICQ Number
Display posts from previous:   
Post new topic   Reply to topic    Visual Basic Forum for Visual Basic Programmers VB Forum Index » Knowledge Base All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Visual Basic Forum runs phpBB | Forum Template © iOptional
VB Resources | SSL | Visual Basic