View Full Version : Cool email example! how do I change it?


jackie77
08-30-2007, 01:36 AM
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?


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

Ian Mac
08-30-2007, 02:48 AM
Jackie,

You need to add SenderName:

With MailOutLook
.SenderName = "The name you want"
.BodyFormat = olFormatRichText

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

Cheers,

jackie77
08-30-2007, 08:28 AM
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?

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

Ian Mac
08-30-2007, 01:31 PM
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.

jackie77
08-31-2007, 03:03 AM
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

Ian Mac
08-31-2007, 03:59 AM
My bad, I didn't read the help files at all it would seem.

Use

.SentOnBehalfOfName = "jackie@tjmcconnells.com"

However it was all in the helpfiles!!

jackie77
08-31-2007, 06:06 AM
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