Solved

Validating Users in Outlook vbscript:

Posted on 2002-06-22
1
800 Views
Last Modified: 2008-03-10
I have a vbscript automating mailsending through Outlook.

dim conn
dim rs

On Error Resume Next

set conn = createobject("ADODB.Connection")

conn.connectionstring="driver={SQL Server};server=t23ola;uid=sa;pwd=;database=dev"
conn.open

Set rs = CreateObject("ADODB.Recordset")

rs.open "SELECT MessageID, MailFrom, MailTo, MailSent FROM tbMessages WHERE MailSent = 0",conn

Do while not rs.eof
 
Set myOlApp = CreateObject("Outlook.Application")
Set myItem = myOlApp.CreateItem(MailItem)
myItem.SentOnBehalfOfName = rs.fields("MailFrom")
myItem.To = rs.fields("MailTo")
myItem.Send

If myItem.Sent = True Then
conn.Execute "UPDATE tbMessages SET MailSent = 1 WHERE MessageID = " & rs.fields("MessageID")
End If
       
rs.movenext
loop

My concern is that there might be names or e-mail-addresses in the MailFrom - field
that is not valid Exchange-users.

In that case I get a dialog 'Check Names'.

I would like to make a validation before setting SentOnBehalfOfName.
If it's not a valid Exchange-user then I would put in a default user instead.
0
Comment
Question by:nr V
1 Comment
 
LVL 16

Accepted Solution

by:
Neo_mvps earned 200 total points
ID: 7101612
Not sure if this will work, but you might want to try...


Set myOlApp = CreateObject("Outlook.Application")
Set myItem = myOlApp.CreateItem(MailItem)
Set objSender = myItem.Recipients.Add ( rs.fields("MailFrom")

objSender.Type = olOriginator
objSender.Resolve

If Not objSender.Resolved Then
  ' Remove this record from the mailitem
End If

myItem.To = rs.fields("MailTo")
myItem.Send


If this doesn't work, then I would create two mailitems.  One is the one you want to send and another is temporary mail item that allows you to add the mailfrom address to the recipients object and then see if it resolves.  If it resolves and you check the email address where it resolves to a X400 address, then add the record to the one you are going to send and toss the temporary mailitem.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Get an idea of what you should include in an email disclaimer with these Top 5 email disclaimer tips.
Check out this infographic on what you need to make a good email signature that will work perfectly for your organization.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now