Cool email example! how do I change it?

jackie77

Jackie
Local time
Today, 20:58
Joined
Jul 18, 2007
Messages
85
Hi all :)

I found a great email example on the web written by blue claw database designs see code below and (I have also attched the file for others to use)what I am looking to do is to get it to send using the out going email address I specify, I have two email address running out of outlook and one is just a sending accounts how do I specify which one to use?


Code:
Option Compare Database

Private Sub Command20_Click()

        Dim mess_body As String
        Dim appOutLook As Outlook.Application
        Dim MailOutLook As Outlook.MailItem
        Set appOutLook = CreateObject("Outlook.Application")
        Set MailOutLook = appOutLook.CreateItem(olMailItem)
            
            Set appOutLook = CreateObject("Outlook.Application")
            Set MailOutLook = appOutLook.CreateItem(olMailItem)
            With MailOutLook
            .BodyFormat = olFormatRichText
            .To = Me.Email_Address
            .Subject = Me.Mess_Subject
            .HTMLBody = Me.Mess_Text
            If Left(Me.Mail_Attachment_Path, 1) <> "<" Then
                .Attachments.Add (Me.Mail_Attachment_Path)
            End If
            '.DeleteAfterSubmit = True   'This would let Outlook send th note without storing it in your sent bin
            .Send
            End With
            'MsgBox MailOutLook.Body
            Exit Sub
email_error:
            MsgBox "An error was encountered." & vbCrLf & "The error message is: " & Err.Description
            Resume Error_out
Error_out:
End Sub

Thanks

Jackie
 

Attachments

Jackie,

You need to add SenderName:

Code:
With MailOutLook
            [b].SenderName = "The name you want"[/b]
            .BodyFormat = olFormatRichText

Change "The name you want" to a name from your address book or the actual email address.

Cheers,
 
Hi Ian thanks for the reply

I have added the code (see below) but I am getting a compile error :( which states "can't assign to read only property" any ideas?

Code:
Private Sub Command20_Click()

        Dim mess_body As String
        Dim appOutLook As Outlook.Application
        Dim MailOutLook As Outlook.MailItem
        Set appOutLook = CreateObject("Outlook.Application")
        Set MailOutLook = appOutLook.CreateItem(olMailItem)
            
            Set appOutLook = CreateObject("Outlook.Application")
            Set MailOutLook = appOutLook.CreateItem(olMailItem)
            With MailOutLook
            .SenderName = "jackie@tjmcconnells.com"
            .BodyFormat = olFormatRichText
            .To = Me.Email_Address
            .Subject = Me.Mess_Subject
            .HTMLBody = Me.Mess_Text
            If Left(Me.Mail_Attachment_Path, 1) <> "<" Then
                .Attachments.Add (Me.Mail_Attachment_Path)
            End If
            '.DeleteAfterSubmit = True   'This would let Outlook send th note without storing it in your sent bin
            .Send
            End With
            'MsgBox MailOutLook.Body
            Exit Sub
email_error:
            MsgBox "An error was encountered." & vbCrLf & "The error message is: " & Err.Description
            Resume Error_out
Error_out:
End Sub

Jackie
 
Ah, Jackie, you found me out.

I read the help files and it said 'a name from your address book' I gueesed at the 'or email' bit :o

I suppose it depends how your email is set up, I wouldn't know how to use the Glodal Address List (GAL) in outlook. I am assuming you are using Outlook Exchange at work.
If someone can help me out on this???

Have you tried adding the details to your address book in Outlook? Or adding what gets displayed in outlook i.e. mine is 'MacConnell, Ian (KAI Other Stuff)'
May work.
 
Thanks Ian, I tried adding it to my address book etc, but still coming up with the same error

anyone have any other ideas?

Jackie
 
My bad, I didn't read the help files at all it would seem.

Use

Code:
.SentOnBehalfOfName  = "jackie@tjmcconnells.com"

However it was all in the helpfiles!!
 
Thanks Ian for having a look I have added this now and it still sends with the default email address but does state beside it that the message is being sent on behalf of my email address so that will work fine for me

Many thanks for your help

Jackie
 

Users who are viewing this thread

Back
Top Bottom