Outlook Object can't set the From property of a mail item

H

homecinemauk

I am using an outlook object in the following way to send a email from
excel:

Sub sendmessage()

Dim OutApp As Object
Dim OutMail As Object

Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)

With OutMail
.Subject = "hi"
.To = "(e-mail address removed)"
.from ="(e-mail address removed)" ' complains HERE!
.Body = "yes this is a test!"
.Attachments.Add ("C:\Documents and Settings\user\Desktop
\doc.xls") ' Must be complete path
.Save
End With

Set OutMail = Nothing

end sub

I am sending via a company outlook account. However, the options in a
new mail item allow me to send a mail item with a different sender so
that the mail is not personalised and all replies can be processed
according to rules:

When running the code a message complains of this method or property
not being available to the object.

Any takers???
 
S

Sue Mosher [MVP-Outlook]

A glance at the object browser would tell you that the MailItem object has no From property.

Outlook 2007 adds a MailItem.SendUsingAccount property.

For earlier versions, Outlook provides no direct way to change the account for an outgoing message. These are known workarounds using native Outlook functionality:

1) If the user has Outlook 2002/3 and is not using WordMail as the editor, you set the sending account using CommandBars techniques. See http://www.outlookcode.com/codedetail.aspx?id=889 for sample code.

2) In an Exchange environment where you want to use another user's mailbox as the From address, set the MailItem.SentOnBehalfOfName property. If you do not want the current user's name to appear in the message at all, the Exchange administrator must grant Send As permission on the other user's mailbox.

3) If you're mainly concerned about replies to your message going to the correct place, add the desired reply address to the MailItem.ReplyRecipients collection.

The third-party Redemption ( http://www.dimastr.com/redemption/ ) library adds two other solutions:

4) Set an RFC822 header property, as described at http://www.dimastr.com/redemption/faq.htm#14

5) Set the RDOMail.Account property, as described at http://www.dimastr.com/redemption/rdo/RDOMail.htm


--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/article.aspx?id=54
 
H

homecinemauk

As i have used the following:

Does this return a general object or is it in fact a Malitem object.
It seems that this is just a function/method of the
Outlook.Application.

My ide doesn't seem to recognise these objects and their methods in
the same way using the dot operator - can i change this?

I executing using this code from excel and have managed to get round
the security manager with a plugin - does this change anything?

Thanking you kindly,

Dean.
 
S

Sue Mosher [MVP-Outlook]

Sounds like you haven't yet used Tools | References to add a reference to the Microsoft Outlook object.
--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/article.aspx?id=54
 
H

homecinemauk

Sounds like you haven't yet used Tools | References to add a reference to the Microsoft Outlook object.
--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/article.aspx?id=54
Thank you for your help...it looks like there is a lot more going on
that's wrong than I thought. I included the reference to Outlook 11.0
and this have solved the object access.

However, when using this method:

Dim OutApp As Outlook.Application
Dim OutMail As Outlook.MailItem

Set OutApp = Outlook.Application
Set OutMail = OutApp.CreateItem(olMailItem)

With OutMail
.Subject = "Testing babe!"
.To = email
.Attachments.Add (filepath)
.BodyFormat = olFormatHTML
.HTMLBody = letter1()
.Save
End With

Set OutMail = Nothing

I can't seem to see the link in to the mailitem object i am creating
the SentOnBehalfOfName property or indeed the replyrecipients
collection.

I certainly DO have rights to send on behalf of another email account
as i am able to change the 'options' in the message to include 'from'
and change it there - how do i access this method or property.

At this moment in time i would be just as happy to be able to default
sending info temporarily while i do the bulk send otherwise i am
stuck.

Kind Regards,
 
S

Sue Mosher [MVP-Outlook]

I don't know what you mean by "see the link in to the mailitem object." The usage is standard object/string property syntax:

OutMail.SentOnBehalfOfName = "Whoever"

or

OutMail.ReplyRecipients.Add "(e-mail address removed)"

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/article.aspx?id=54
 
H

homecinemauk

Thank you for that!

However you did say that if i had permissions to send as someone else
it could be done.

You have already been so helpful but if you could point me in the
right direction i would be most obliged!

Thank you!
 
S

Sue Mosher [MVP-Outlook]

My last message showed that you the correct syntax using your own variable name. Did you try it?

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/article.aspx?id=54
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top