Solved

Send email attachment using VB?

Posted on 2003-10-29
5
1,399 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
Comment Utility
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
Comment Utility
Also, there is an .Attachment collection if i rememeber well in Outlook
0
 

Author Comment

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

Author Comment

by:Mhairijm
Comment Utility
.Attachment works a treat, thanks!
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
Comment Utility
Glad to help.
Thanks for "A" grade.
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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 process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

772 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

8 Experts available now in Live!

Get 1:1 Help Now