Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Select Outlook Account

Status
Not open for further replies.

AlanDI1

Programmer
Apr 20, 2003
56
I have an Access VBA process that reads a table and creates a bunch of e-mails. Fairly straight forward.

*****************************************************
Dim objOutlook As New Outlook.Application
Dim objOutlookMsg As Outlook.MailItem

On Error GoTo ErrorMsgs

' Create the Outlook session.
Set objOutlook = CreateObject("Outlook.Application")
' Create the message.
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
With objOutlookMsg
.To = "test@test.net"
' Set the Subject, Bodyof the message.
.Subject = "Test ID"
.Body = "Here is your New ID and Password" & vbCrLf
.Send
End With

Set objOutlookMsg = Nothing
Set objOutlook = Nothing
**********************************************************

I do not want the "from" in the e-mail that is received by the recipient to have my e-mail address but that of the system administrator.

1 - is it possible to hard code a "from" e-mail address when generating the message? The "SentOnBehalfOfName" shows both my e-mail address and the system administrator, that's not good. The "SenderEmailAddress" seems to be read only.

2 - if #1 is not possible, I can create a second account on the machine that will run this process but how do I tell the process creating the e-mail which account to use?

Thanks
 
[ol][li]No, not with Outlook/Exchange. You can find another SMTP engine that will do this (this is how a SPAM virus operates on a single machine.)[/li][li]If you have authoring rights on the System Administrator account you can switch the [tt]NameSpace()[/tt] of the [tt]Outlook.Application[/tt] object from your profile (default) to the System Administrator account.[/li][/ol]

Hope this helps,
CMP

Not sure if this works, I only skimmed the book that came with the software.
 
Thanks CMP -

I actually changed to using CDO. It works like a charm once you get the configuration correct.

Appreciate your help.
 
Hi

could you give me the vode as above with CDO?

EasyIT
 
Sure but remember the following before you start.

The code works for the following assumptions:

1 - I am sending the mail message through an external ISP.

2 - My ID and Password are filled under "sendusername" and "sendpassword".

3 - Either the DNS Name or the IP Address of the SMTP server is filled in under "smtpserver"

4 - The "From" and the "To" in the message MUST look like really address. That is "Test@Test.com". I tried "TestAddress" and it knew that could not be an e-mail address and failed. Of course it does not check the existance of the address just the format.

5 - This proc is passed three parameters for the purpose of the message I am sending, that can/should be changed as needed.

6 - Commented out MsgBox was so I could see what was actually being set during configuration.

The Code is as follows:
**********************************************************
Function CDOSendEMail(pcEMailAddr As String, pcUserID As String, pcPassword As String) As Boolean
' Format E-Mail Message and send

Set oMail = CreateObject("CDO.Message")
Set oMailConfig = CreateObject("CDO.Configuration")

oMailConfig.Fields.Item(" = 2
oMailConfig.Fields.Item(" = "MyISP.SMTP.Server.Com"
oMailConfig.Fields.Item(" = 1
oMailConfig.Fields.Item(" = "myIDonISP"
oMailConfig.Fields.Item(" = "myPasswordonISP"
oMailConfig.Fields.Item(" = 25
oMailConfig.Fields.Item(" = False
oMailConfig.Fields.Item(" = 60
' MsgBox oMailConfig.Fields.Item(" & " " & _
oMailConfig.Fields.Item(" & " " & _
oMailConfig.Fields.Item(" & " " & _
oMailConfig.Fields.Item(" & " " & _
oMailConfig.Fields.Item(" & " " & _
oMailConfig.Fields.Item(" & " " & _
oMailConfig.Fields.Item(" & " " & _
oMailConfig.Fields.Item("
oMailConfig.Fields.Update
oMail.Configuration = oMailConfig

oMail.From = "My Name <MyName@MyIsp.Net>"
oMail.To = pcEMailAddr
oMail.Subject = "User ID"
oMail.TextBody = "This message was sent to " & pcEMailAddr & vbCrLf & vbCrLf & vbCrLf & _
"A User ID and Password has been assigned to you for use as follows " & vbCrLf & vbCrLf & vbCrLf & _
"Your User ID is: " & pcUserID & vbCrLf & vbCrLf & _
"Your Password is: " & pcPassword & vbCrLf & vbCrLf & vbCrLf & _
"Please contact the System Administrator is you have questions or issues accessing Pbviews"
oMail.Send
Set oMail = Nothing
Set oMailConfig = Nothing

CDOSendEMail = True

End Function
*******************************************************
Good Lock
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top