Solved

Send email attachment using VB?

Posted on 2003-10-29
5
1,403 Views
Last Modified: 2010-05-01
Hi. I have a piece of code that sends an email via Outlook:

Private Sub SendEmail(strProblem)

On Error GoTo errEmail

Dim objSession      As Object
Dim objMessage      As Object
Dim objRecipient    As Object
Dim strProblemFull  As String
Dim nRow            As Integer
Dim strProfileInfo  As String
Dim strMailbox      As String
Dim sSubject        As String
Dim objMsg          As Object
Dim sFrom           As String

   
   For nRow = 1 To nEmails
       
        sTemp = ""
        ' get list of emails for the report type and group
        lRet = GetPrivateProfileString("Email", "Subject", "", sTemp, Len(sTemp), sINI)
        'Set the properties of the message object
        sSubject = Replace(Trim$(sTemp), Chr(0), "")
       
        sTemp = ""
        ' get list of emails for the report type and group
        lRet = GetPrivateProfileString("Email", "from", "", sTemp, Len(sTemp), sINI)
        'Set the properties of the message object
        sFrom = Replace(Trim$(sTemp), Chr(0), "")
       
        sTemp = ""
        ' get list of emails for the report type and group
        lRet = GetPrivateProfileString("Email", "To" & CStr(nRow), "", sTemp, Len(sTemp), sINI)
       
        Set objMsg = CreateObject("CDO.Message")
        objMsg.From = sFrom
        objMsg.To = Replace(Trim$(sTemp), Chr(0), "")
        objMsg.Subject = sSubject
        objMsg.TextBody = strProblem
        objMsg.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "abzexmb1"
        objMsg.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
        objMsg.Configuration.Fields.Update
        objMsg.Send
        Set objMsg = Nothing

    Next
       
     
Exit Sub

The details for the email (to, from etc) are held in an ini file:
[email]

noofEmails=1
frequency=7
subject=
from=
to1=

This works fine but I want to be able to send an attachment along with the email (access db). Does anyone know how to do this?

Thanks.

0
Comment
Question by:Mhairijm
  • 3
  • 2
5 Comments
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 9642695
you could use this exelent a free component:
http://www.freevbcode.com/ShowCode.Asp?ID=109
0
 
LVL 16

Accepted Solution

by:
Richie_Simonetti earned 200 total points
ID: 9642714
Also, there is an .Attachment collection if i rememeber well in Outlook
0
 

Author Comment

by:Mhairijm
ID: 9642748
Thanks. I'll have a look and let you know how I get on.
0
 

Author Comment

by:Mhairijm
ID: 9643427
.Attachment works a treat, thanks!
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 9643624
Glad to help.
Thanks for "A" grade.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

733 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