?
Solved

Validating Users in Outlook vbscript:

Posted on 2002-06-22
1
Medium Priority
?
831 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 16

Accepted Solution

by:
Neo_mvps earned 800 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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

This article will help to fix the below errors for MS Exchange Server 2013 I. Certificate error "name on the security certificate is invalid or does not match the name of the site" II. Out of Office not working III. Make Internal URLs and Externa…
Outlook for dependable use in a very small business   This article is about using the Outlook application (part of Microsoft Office) in a very small business, or for homeowners where dependability and reliability are critical requirements. This …
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: …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Suggested Courses

770 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