Solved Sending Email with Signature (1 Viewer)

Teggun

Registered User.
Local time
Today, 16:39
Joined
Aug 30, 2019
Messages
33
Hi guys, I'm trying to prepare an automatic email for sending when performing an action, and everything works fine but the default signature I have established in Outlook disappears when adding a body using VBA. I tried to capture the signature before editting the body and add it after, but it does not keep the images and I feel like this is not the propper way to do this...

Code:
Private Sub cmdSend_Click()
'\Setting the variables
        Dim AppOutLook As Object
        Dim MailOutLook As Object
        Dim rsOffers As Recordset
        Dim strCostumer As String
        Dim strPath As String
        Dim strFilter As String
        Dim strFile As String
        Dim strGood As String
        Dim strMsg As String
        Dim strUserP As String
        Dim strOC As String
        Dim strSignature As String

'\Defining variables values to get the path and others...
If Not IsNull(Me.txtOC) Then
    If DCount("OC", "tblOffers", "OC = " & Me.txtOC) > 0 Then
        strOC = me.txtOC
        Set rsOffers = CurrentDb.OpenRecordset("tblOffers", dbOpenDynaset)
        rsOffers.FindLast "OC = " & strOC
        strCostumer = rsOffers.Fields("IDCostumer_FK")
       
        If Left(CurrentProject.Path, 14) = "C:\Users\ocoll\" Then
            strUserP = "C:\Users\ocoll\"
        ElseIf Left(CurrentProject.Path, 14) = "C:\Users\Alex\" Then
            strUserP = "C:\Users\Alex\OneDrive\"
        Else
            MsgBox "¡Can't send an email from this device!"
            Exit Sub
        End If
       
        On Error Resume Next
   
        Set AppOutLook = GetObject(, "Outlook.Application")
   
        If Err Then
            Set AppOutLook = CreateObject("Outlook.Application")
        End If
       
        Set MailOutLook = AppOutLook.CreateItem(olMailItem)
       
        strGood = IIf(Time() > 4 And Time() < 13, "Good morning,", "Good evening,")
        strMsg = strGood & Chr(13) & Chr(10) & "TEST TEST TEST"
        strPath = "DOCUMENTS\" & DLookup("FolderName", "tblCostumers", "IDCostumer = " & strCostumer) & "\"
        strFilter = DLookup("CostumerCode", "tblCostumers", "IDCostumer = " & strCostumer) & "_" & strOC & ".pdf"
        strFile = Dir(strUserP & strPath & strFilter)
   
        If strFile <> "" Then
   
            Set AppOutLook = CreateObject("Outlook.Application")
            Set MailOutLook = AppOutLook.CreateItem(olMailItem)

'\Displaying the mail first to capture the default signature
            With MailOutLook
                .Display
                strSignature = .Body

'\Creating the mail
                .BodyFormat = olFormatRichText
                .To = DLookup("Mail", "tblCostumers", "IDCostumer = " & strCostumer)
                '.cc = ""
                '.bcc = ""
                .Subject = "OFFER Nº" & Me.txtOC
                .body = strMsg & vbNewLine & strSignature
                .Attachments.Add (strPath & strFile)
                .Display
            End With

        Else
            MsgBox "Could not find the file " & strPath & strFilter & " found." & vbCrLf
            Exit Sub
        End If

    Else
        MsgBox "¡This offer does not exist!"
    End If
Else
    MsgBox "¡Define offer number to send the mail!"
End If
End Sub

I really need to add an image as well in the mentioned signature and can't find the way to do so, but I would prefer to just make the signature display using a command...
Isn't there a command to call the default signature and add it in the .body? If not, how could I call and add an embed image in the body?

Thanks guys for your time and help. Greetings.
 
Last edited:

Teggun

Registered User.
Local time
Today, 16:39
Joined
Aug 30, 2019
Messages
33
It works like charm, excaly what I was looking for. Thanks a lot!
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 22:39
Joined
May 7, 2009
Messages
19,237
you're welcome!
 

Users who are viewing this thread

Top Bottom