Creating email in VB, how do I change the "From" field?

charliemopps

Registered User.
Local time
Today, 01:27
Joined
Feb 24, 2009
Messages
40
I've got code to create an email in VB. It works flawlessly... My one problem is that I don't want to send the email from my default account... I want to send it from my departments account. I have permissions to do so... but I can not find the control to put the address in my code.

There is one called "SenderName" but it errors out as read only.

Any ideas?
 
Hi,
Here is some code I have used before:

Dim oApp As Object
Dim oMessage As MailItem, oRec As Recipient
Set oApp = CreateObject("Outlook.Application")
Set oMessage = oApp.CreateItem(olMailItem)
oMessage.Display

Set oRec = oMessage.Recipients.Add(MAIL ADDRESS HERE)
oRec.Type = olTo
oMessage.Subject = SUBJECT HERE
oMessage.Body = MESSAGE HERE

Regards
JD
 
Here's what I have... it works... but I can't figure out what the from field is...


Code:
Public Function CreateMailItem(strTo As String, strSubject As String, strBody As String)
    Dim appOutlook  As Outlook.Application
    Dim olItem      As Outlook.MailItem
 
    Set appOutlook = New Outlook.Application
 
    Set olItem = appOutlook.CreateItem(olMailItem)
    olItem.Display
 
    olItem.To = strTo
    olItem.Subject = strSubject
    olItem.Body = strBody
    olItem.Importance = olImportanceHigh
 
    Set appOutlook = Nothing
End Function

I need something like:
olItem.From
but there is no such thing...
 
Just looked through the available parameters for the olMailItem type and there is something called .SenderEmailAddress - this might be worth investigating.
 
that just returns an error. I looked it up... that that property is for incoming mail. You read it to see where it came from.
 
GOT IT!! wooo!

olItem.SentOnBehalfOfName =

Thanks for posting back with your success. It may help someone else in the future :)

thumbsup.png
 
ok, wierd... it worked twice and then now it doesnt. GRRRRR

edit.. ok, no it works. I had an error elsewhere in my code. SentOnBehalfOfName is what you want.
 
Bob is quite right about posting solutions for future users; I just came onto the site with the same question and got the answer p.d.q.!
 

Users who are viewing this thread

Back
Top Bottom