Results 1 to 13 of 13

Thread: Email a file from hard disk

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2002
    Location
    Bangladesh
    Posts
    106

    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

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Using Outlook

    VB Code:
    1. Private Sub SendMailMessage(DisplayMsg As Boolean, Receiver As String, Optional
    2.     AttachmentPath)
    3.     Dim objOutlook As Outlook.Application
    4.     Dim objOutlookMsg As Outlook.MailItem
    5.     Dim objOutlookRecip As Outlook.Recipient
    6.     Dim objOutlookAttach As Outlook.Attachment
    7.     Dim CallDescription As String
    8.  
    9. ' Create the Outlook session.
    10.     Set objOutlook = CreateObject("Outlook.Application")
    11.  
    12. ' Create the message.
    13.     Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
    14.  
    15.     With objOutlookMsg
    16. ' Add the To recipient(s) to the message.
    17.         Set objOutlookRecip = .Recipients.Add(Receiver)
    18.         objOutlookRecip.Type = olTo
    19.  
    20. ' Add the CC recipient(s) to the message.
    21.         Set objOutlookRecip = .Recipients.Add("[email protected]")
    22.         objOutlookRecip.Type = olCC
    23.  
    24. ' Set the Subject, Body, and Importance of the message.
    25.         .Subject = "Replace this String With your subject Or variable"
    26.  
    27.         .Body = "replace this String With your subject Or variabele"
    28.         .Body = .Body & vbCrLf & "In this manner you can create a body larger than 256 characters"
    29.  
    30. ' Add attachments to the message.
    31.         If Not IsMissing(AttachmentPath) Then
    32.             Set objOutlookAttach = .Attachments.Add("c:\program files\myfile.exe")
    33.         End If
    34.  
    35. ' Resolve each Recipient's name.
    36.         For Each objOutlookRecip In .Recipients
    37.             objOutlookRecip.Resolve
    38.         Next
    39.  
    40. ' Should we display the message before sending?
    41.         If DisplayMsg Then
    42.             .Display
    43.         Else
    44.             .Send
    45.         End If
    46.  
    47.     End With
    48.  
    49.     Set objOutlook = Nothing
    50. End Sub

  3. #3
    Addicted Member
    Join Date
    Sep 2002
    Posts
    251

    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!

  4. #4
    Frenzied Member
    Join Date
    Jan 2001
    Location
    Newbury, UK
    Posts
    1,878
    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:
    1. MAPISession1.SignOn
    2.         MAPIMessages1.SessionID = MAPISession1.SessionID
    3.         MAPIMessages1.Compose
    4.         MAPIMessages1.RecipDisplayName = "[email protected]"
    5.         MAPIMessages1.MsgSubject = "My Subject"
    6.         MAPIMessages1.MsgNoteText = "My body"
    7.         MAPIMessages1.ResolveName
    8.         MAPIMessages1.Send
    9.         MAPISession1.SignOff

  5. #5
    Addicted Member
    Join Date
    Sep 2002
    Posts
    251

    Hail!

    Mine is outlook express! =-)


    I will try this code...

    Thanks for your time!

    Elminster

  6. #6
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    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....

  7. #7
    Addicted Member
    Join Date
    Sep 2002
    Posts
    251

    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

  8. #8
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    Well

    VB Code:
    1. '*******************************************************************************
    2. ' SENDMESSAGETHRUEXPRESS (SUB)
    3. '
    4. ' DESCRIPTION:
    5. ' ACTUALLY SEND THE EMAIL MESSAGE THRU EXPRESS
    6. '*******************************************************************************
    7.  
    8. Sub SENDMESSAGETHRUEXPRESS(DisplayMsg As Boolean, Optional AttachmentPath)
    9.    
    10.     MAPISession1.SignOn
    11.    
    12.     With Me.MAPIMessages1
    13.        
    14.         .SessionID = MAPISession1.SessionID
    15.        
    16.         .MsgIndex = -1
    17.        
    18.         .Compose
    19.        
    20.         .MsgSubject = Me.txtSubject
    21.        
    22.         .RecipType = mapToList
    23.        
    24.         .RecipDisplayName = Me.txtAddressTO
    25.        
    26.         .RecipAddress = Me.txtAddressTO
    27.        
    28.         ' SHOW THE ADDRESS BOOK WITH THE SELECTED RECIPIENT(S)
    29.        
    30.         ' 0=NO EDIT FIELDS, 1=TO, 2=(TO AND CC), 3=(TO, CC AND BLIND CC),
    31.         ' 4=ONLY THOSE SUPPORTED BY MESSAGING SYSTEM WILL BE SHOWN
    32.        
    33.         .AddressEditFieldCount = 1
    34.        
    35.         .MsgNoteText = Me.txtMsg
    36.        
    37.         ' ADD ATTACHMENT FILE IF THE LABEL CONTAINS A SELECTED FILE
    38.        
    39.         If Len(Me.lblAttachment.Caption) > 0 And Me.lblAttachment.Caption > " " Then
    40.            
    41.             .AttachmentPosition = 0
    42.            
    43.             .AttachmentName = lblAttachment
    44.            
    45.             .AttachmentPathName = lblAttachment
    46.            
    47.             .AttachmentType = mapEOLE
    48.            
    49.         End If
    50.        
    51.         ' SEND THE EMAIL
    52.        
    53.         .Send
    54.        
    55.     End With
    56.    
    57.     MAPISession1.SignOff
    58.    
    59. End Sub
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  9. #9
    Frenzied Member
    Join Date
    Jan 2001
    Location
    Newbury, UK
    Posts
    1,878
    More than one attachment:
    VB Code:
    1. With MAPIMessages1
    2.         .AttachmentIndex = 0
    3.         .AttachmentPosition = 0
    4.         .AttachmentPathName = "c:\temp\test.txt"
    5.         .AttachmentIndex = 1
    6.         .AttachmentPosition = 1
    7.         .AttachmentPathName = "c:\temp\x01.txt"
    8. End With

  10. #10
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    Well

    So did you get it to work?
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  11. #11
    Addicted Member
    Join Date
    Sep 2002
    Posts
    251

    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

  12. #12
    Addicted Member
    Join Date
    Sep 2002
    Posts
    251

    Hello!

    Good Morning!

    Its working really really fine!

    Really thanks!

    I love this code.. =-)


    Elminster

  13. #13
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    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
  •  



Click Here to Expand Forum to Full Width