Solved

send auto-mail with file attachment from local drive

Posted on 2001-09-03
6
328 Views
Last Modified: 2010-08-05
My Problem:
I have to take a file from Disk (Drive C:\) and take this file as an attachment to an mail and send it automatical.


0
Comment
Question by:Schobert
  • 4
6 Comments
 
LVL 12

Accepted Solution

by:
Paurths earned 300 total points
Comment Utility
hi Schobert,

u can use the open/save dialog to pick the file, u'll find an example here : http://www.mvps.org/access/api/api0001.htm


and here is the code for sending email with attachment: (in this example the retrieved file is strFileSelected)

Private Sub cmdSending_Click()
Dim rs As DAO.Recordset
Dim strMsg As String
Dim strSub As String

    strMsg = "Type the email body..."
    strSub = "Type the subject for the message here..."

    SendMessage "person@where.com", strMsg, strSub, strFileSelected
           
End Sub


Private Sub SendMessage(strTo As String, strMsg As String, strSub As String, Optional AttachmentPath)
  Dim objOutlook As Outlook.Application
  Dim objOutlookMsg As Outlook.MailItem
  Dim objOutlookRecip As Outlook.Recipient
  Dim objOutlookAttach As Outlook.Attachment

  ' 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(strTo)
     objOutlookRecip.Type = olTo

     ' Set the Subject, Body, and Importance of the message.
     .Subject = strSub
     .Body = strMsg & vbCrLf & vbCrLf
     .Importance = olImportanceHigh  'High importance

     ' Add attachments to the message.
     If Not IsMissing(AttachmentPath) Then
        Set objOutlookAttach = .Attachments.Add(AttachmentPath)
     End If

     ' Resolve each Recipient's name.
     For Each objOutlookRecip In .Recipients
        objOutlookRecip.Resolve
        If Not objOutlookRecip.Resolve Then
        objOutlookMsg.Display
     End If
     Next
     .Send

  End With
  Set objOutlookMsg = Nothing
  Set objOutlook = Nothing

End Sub


hope this  helps,
Ricky
0
 
LVL 12

Expert Comment

by:Paurths
Comment Utility
btw, u should adjust the open/save function so that it will return the path and name of the selected file:


Private Sub cmdSending_Click()
Dim strMsg As String
Dim strSub As String
dim strFileSelected as variant

   strFileSelected = TestIt()
   strMsg = "Type the email body..."
   strSub = "Type the subject for the message here..."

   SendMessage "person@where.com", strMsg, strSub, strFileSelected
           
End Sub





Function TestIt() as variant
    Dim strFilter As String
    Dim lngFlags As Long
    strFilter = ahtAddFilterItem(strFilter, "Access Files (*.mda, *.mdb)", _
                    "*.MDA;*.MDB")
    strFilter = ahtAddFilterItem(strFilter, "dBASE Files (*.dbf)", "*.DBF")
    strFilter = ahtAddFilterItem(strFilter, "Text Files (*.txt)", "*.TXT")
    strFilter = ahtAddFilterItem(strFilter, "All Files (*.*)", "*.*")
    MsgBox "You selected: " & ahtCommonFileOpenSave(InitialDir:="C:\", _
        Filter:=strFilter, FilterIndex:=3, Flags:=lngFlags, _
        DialogTitle:="Hello! Open Me!")
    ' Since you passed in a variable for lngFlags,
    ' the function places the output flags value in the variable.
    Debug.Print Hex(lngFlags)
End Function
0
 
LVL 12

Expert Comment

by:Paurths
Comment Utility
u can also adjust the filter set in the dialog (and an adjustment to the returning value that i forgot...)
only choosing excel files:

Function TestIt() As Variant
    Dim strFilter As String
    Dim lngFlags As Long
    strFilter = ahtAddFilterItem(strFilter, "Excel Files (*.xls)", _
                    "*.xls")
    TestIt = ahtCommonFileOpenSave(InitialDir:=strLoc, _
        Filter:=strFilter, FilterIndex:=3, Flags:=lngFlags, _
        DialogTitle:="Hello! Open Me!")

End Function
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 2

Expert Comment

by:JamesMayfield
Comment Utility
What email program are you using? Does it have to serve various mail programs?

This is actually a fairly simple one. Answer the above two questions and I'll give you some code that does it.
0
 

Author Comment

by:Schobert
Comment Utility
Hi,
It was possilbe to solve the problem as I have seen Your proposal, but the code worked not emediately on my computer ( I thinke it depends not on Your code).
Thanke You for Your quick help !
best regards,
Sigi Schobert
0
 
LVL 12

Expert Comment

by:Paurths
Comment Utility
hi Schobert,

glad it helped u with sending those emails,
i am wondering a little why this code is only worth a B-grade.
It is excellent code i provided.
Please dont feel like this is attacking you in anyway, it is not.
I am just curious.

cheers
Ricky
0

Featured Post

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Join & Write a Comment

It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now