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
Printable View
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
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. Set objOutlookRecip = .Recipients.Add("[email protected]") 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
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!
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.RecipDisplayName = "[email protected]" MAPIMessages1.MsgSubject = "My Subject" MAPIMessages1.MsgNoteText = "My body" MAPIMessages1.ResolveName MAPIMessages1.Send MAPISession1.SignOff
Mine is outlook express! =-)
I will try this code...
Thanks for your time!
Elminster
If you prefer, I can email you a sample project I created which uses MAPI contrlo to send email... ;)
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
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
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
So did you get it to work?
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
Good Morning!
Its working really really fine!
Really thanks!
I love this code.. =-)
Elminster
Glad you got it to work. ;)