Solved

Validating Users in Outlook vbscript:

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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

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…
Large Outlook files lead to various unwanted errors and corruption issues. Furthermore, large outlook files can also make Outlook take longer to start-up, search, navigate, and shut-down. So, In this article, i will discuss a method to make your Out…
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…
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …

821 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