Avis Junior Poster

Joined: 07 Oct 2003 Posts: 510 Location: India
|
Posted: Aug 2nd, 2004 06:47 AM Post subject: Sending Mail with Attachments |
|
|
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! |
|