[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Validating Users in Outlook vbscript:

Posted on 2002-06-22
1
Medium Priority
?
838 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

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

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…
The core idea of this article is to make you acquainted with the best way in which you can export Exchange mailbox to PST format.
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 …
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

650 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