Solved

Validating Users in Outlook vbscript:

Posted on 2002-06-22
1
805 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This process describes the steps required to Import and Export data from and to .pst files using Exchange 2010. We can use these steps to export data from a user to a .pst file, import data back to the same or a different user, or even import data t…
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
CodeTwo Sync for iCloud (http://www.codetwo.com/sync-for-icloud?sts=6554) automatically synchronizes your Outlook 2016, 2013, 2010 or 2007 folders with iCloud folders available via iCloud Control Panel. This lets you automatically sync them with…

863 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

23 Experts available now in Live!

Get 1:1 Help Now