|
-
Oct 7th, 2002, 03:55 AM
#1
Thread Starter
Lively Member
Email a file from hard disk
Hi,
I want to know that "If I want to make such a project which can email a file from specific path from hard disk to a email address" Could you please help me?
Thanking you
Rummy
-
Oct 7th, 2002, 06:30 AM
#2
Using Outlook
VB Code:
Private Sub SendMailMessage(DisplayMsg As Boolean, Receiver As String, Optional
AttachmentPath)
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment
Dim CallDescription As String
' Create the Outlook session.
Set objOutlook = CreateObject("Outlook.Application")
' Create the message.
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
With objOutlookMsg
' Add the To recipient(s) to the message.
Set objOutlookRecip = .Recipients.Add(Receiver)
objOutlookRecip.Type = olTo
' Add the CC recipient(s) to the message.
objOutlookRecip.Type = olCC
' Set the Subject, Body, and Importance of the message.
.Subject = "Replace this String With your subject Or variable"
.Body = "replace this String With your subject Or variabele"
.Body = .Body & vbCrLf & "In this manner you can create a body larger than 256 characters"
' Add attachments to the message.
If Not IsMissing(AttachmentPath) Then
Set objOutlookAttach = .Attachments.Add("c:\program files\myfile.exe")
End If
' Resolve each Recipient's name.
For Each objOutlookRecip In .Recipients
objOutlookRecip.Resolve
Next
' Should we display the message before sending?
If DisplayMsg Then
.Display
Else
.Send
End If
End With
Set objOutlook = Nothing
End Sub
-
Oct 7th, 2002, 06:52 AM
#3
Addicted Member
Hey!
Hail all!
Plz, what kind of reference and/or components should I get to make this function work?
I am getting an error in "Dim objOutlook As Outlook.Application", telling that its not a user defined type.. =-(
I tryed to put references of outlook and components of mapi, but both didnt helped...
And my component to outlook could not be loaded.. I dont know why.. =-(
Thx guys!
-
Oct 7th, 2002, 07:38 AM
#4
Frenzied Member
Which version of Outlook have you got on your system? Outlook or Outlook Express??
Adding a reference to Microsoft Outlook 9.0 Object Library works.
If you want to use MAPI instead of Outlook, then you need to add the two MAPI controls (MAPI Session and MAPIMessages) to a form (they are not visible at run time) and then use code like:
VB Code:
MAPISession1.SignOn
MAPIMessages1.SessionID = MAPISession1.SessionID
MAPIMessages1.Compose
MAPIMessages1.MsgSubject = "My Subject"
MAPIMessages1.MsgNoteText = "My body"
MAPIMessages1.ResolveName
MAPIMessages1.Send
MAPISession1.SignOff
-
Oct 7th, 2002, 08:21 AM
#5
Addicted Member
Hail!
Mine is outlook express! =-)
I will try this code...
Thanks for your time!
Elminster
-
Oct 7th, 2002, 08:27 AM
#6
PowerPoster
Well
If you prefer, I can email you a sample project I created which uses MAPI contrlo to send email...
Remaining quiet down here !!!
BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....
-
Oct 7th, 2002, 08:32 AM
#7
Addicted Member
Hail Again!
hey man!
I tryed the last code with the mapi thing, and it works perfectly!
I just would like to know if theres a way to send attachment with the mapi object...Because the way that I tryed , only worked with the text body of the email.. And I didnt saw any code to the file attachment... =-(
Thx guys!
Elminster
-
Oct 7th, 2002, 08:34 AM
#8
PowerPoster
Well
VB Code:
'*******************************************************************************
' SENDMESSAGETHRUEXPRESS (SUB)
'
' DESCRIPTION:
' ACTUALLY SEND THE EMAIL MESSAGE THRU EXPRESS
'*******************************************************************************
Sub SENDMESSAGETHRUEXPRESS(DisplayMsg As Boolean, Optional AttachmentPath)
MAPISession1.SignOn
With Me.MAPIMessages1
.SessionID = MAPISession1.SessionID
.MsgIndex = -1
.Compose
.MsgSubject = Me.txtSubject
.RecipType = mapToList
.RecipDisplayName = Me.txtAddressTO
.RecipAddress = Me.txtAddressTO
' SHOW THE ADDRESS BOOK WITH THE SELECTED RECIPIENT(S)
' 0=NO EDIT FIELDS, 1=TO, 2=(TO AND CC), 3=(TO, CC AND BLIND CC),
' 4=ONLY THOSE SUPPORTED BY MESSAGING SYSTEM WILL BE SHOWN
.AddressEditFieldCount = 1
.MsgNoteText = Me.txtMsg
' ADD ATTACHMENT FILE IF THE LABEL CONTAINS A SELECTED FILE
If Len(Me.lblAttachment.Caption) > 0 And Me.lblAttachment.Caption > " " Then
.AttachmentPosition = 0
.AttachmentName = lblAttachment
.AttachmentPathName = lblAttachment
.AttachmentType = mapEOLE
End If
' SEND THE EMAIL
.Send
End With
MAPISession1.SignOff
End Sub
Remaining quiet down here !!!
BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....
-
Oct 7th, 2002, 08:41 AM
#9
Frenzied Member
More than one attachment:
VB Code:
With MAPIMessages1
.AttachmentIndex = 0
.AttachmentPosition = 0
.AttachmentPathName = "c:\temp\test.txt"
.AttachmentIndex = 1
.AttachmentPosition = 1
.AttachmentPathName = "c:\temp\x01.txt"
End With
-
Oct 7th, 2002, 07:03 PM
#10
PowerPoster
Well
So did you get it to work?
Remaining quiet down here !!!
BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....
-
Oct 7th, 2002, 08:34 PM
#11
Addicted Member
Sorry for the long time without reply...
Sorry for the long time without reply...
I was in the work.... I arrived in my home now....=-)
I will try to use the code, and them I will write here what happened....=-) I will just get a bath and have a dinner..=-)
Them I will do it...
Really thanks for you help!
Elminster
-
Oct 8th, 2002, 06:56 AM
#12
Addicted Member
Hello!
Good Morning!
Its working really really fine!
Really thanks!
I love this code.. =-)
Elminster
-
Oct 9th, 2002, 08:55 AM
#13
PowerPoster
Well
Glad you got it to work.
Remaining quiet down here !!!
BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|