Solved

Use vbScript to email info from csv file

Posted on 2004-04-05
8
558 Views
Last Modified: 2016-06-25
Need to establish a vbscript that will pull email addresses from a csv file & and pull parts of message body from same line then proceed to the next address. Prefer to use SMTP from IIS.

Example:
cvs file format:
name,emailaddress,reg
name,emailaddress,reg
name,emailaddress,reg
name,emailaddress,reg
etc

Message would be something like

To: "emailaddress"
From: admin@ourdomain.com
MessageSubject: requested information

Message body

Dear "name"

Thank you...blah blah blah below is the requested information
"reg"

Word in "" are the variables that would need to be pulled from the csv file.

Thanks

0
Comment
Question by:Curtv
[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
  • 4
  • 3
8 Comments
 
LVL 14

Accepted Solution

by:
aelatik earned 350 total points
ID: 10760563
You can use various mailers to accomplish this. I made one that uses the CDO object. You need the set you SMTP adress to get it working.

   
    Dim FSO, TEXTSTREAM, CSV_FILE, CSV_LINES, CSV_ITEMS, CSV_LINE
    Set FSO = CreateObject("Scripting.FileSystemObject")
    Set TEXTSTREAM = FSO.OpenTextFile("c:\temp.csv", 1, False, 0)
        CSV_FILE = TEXTSTREAM.ReadAll
    Set TEXTSTREAM = Nothing
    Set FSO = Nothing
        CSV_LINES = Split(CSV_FILE, vbCrLf)
       
        For Each CSV_LINE In CSV_LINES
            CSV_ITEMS = Split(CSV_LINE, ",")
            Dim X
            X = "Dear " & CSV_ITEMS(0) & vbCrLf
            X = X & "Thank you...blah blah blah below is the requested information" & vbCrLf
            X = X & CSV_ITEMS(2) & vbCrLf
            X = X & " Word in ? are the variables that would need to be pulled from the csv file." & vbCrLf
            X = X & "Thanks"
            Mail CSV_ITEMS(0), CSV_ITEMS(1), X ' Call the mailer
            wscript.echo "Mailed to " & CSV_ITEMS(1)
        Next

Function Mail(M_NAME, M_TO, M_BODY)
    Set Mail = CreateObject("CDO.Message")
    Set CON = CreateObject("CDO.Configuration")
        CON.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "255.255.255.255"
        CON.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
        CON.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
        CON.Fields("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
        CON.Fields.Update
    Set Mail.Configuration = CON
        Mail.From = "admin@ourdomain.com"
        Mail.To = M_TO
        Mail.CC = ""
        Mail.Subject = "requested information"
        Mail.HTMLBody = M_BODY
        Mail.Send
    Set Mail = Nothing
    Set CON = Nothing
End Function
0
 

Author Comment

by:Curtv
ID: 10760968
For educational purposes why are these pointing to microsoft

        CON.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "255.255.255.255"
        CON.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
        CON.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
        CON.Fields("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60

Thanks for your fast response. I will try it out.

0
 
LVL 14

Expert Comment

by:aelatik
ID: 10763094
Curtv,

It looks like it is pointing to Microsoft but it isn't. This "http://schemas.microsoft.com/cdo/configuration/smtpserver" is a field/object name.
I had the same confusion in the beginning to.
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

Author Comment

by:Curtv
ID: 10766589
aelatik

Forgive my newbieness, perl guy.

I was looking for a way to send html mail. I was following http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_10239836.html?query=format+text+html&searchType=topic, I must have done something wrong, got no text instead of html. From other postings there needs to be a Mail.BodyFormat = 0

For clarity is there a simple way to bold or underline one of the variables?

Thanks
0
 
LVL 14

Expert Comment

by:aelatik
ID: 10766918
Mail.BodyFormat = 0 is for CDONTS, this is the CDO object ( Windows 2000 and Windows XP ).

Does your mailclient show HTML formatted emails ?
0
 
LVL 14

Expert Comment

by:aelatik
ID: 10766944
I use exactly the same code and it works with me.

Do it like this :

            X = "<b>Dear</b> " & CSV_ITEMS(0) & vbCrLf
            X = X & "Thank you...blah blah blah below is the requested information" & vbCrLf
            X = X & CSV_ITEMS(2) & vbCrLf
            X = X & " Word in ? are the variables that would need to be pulled from the csv file." & vbCrLf
            X = X & "<b>Thanks</b>"
0
 

Author Comment

by:Curtv
ID: 10767200
Ah, making a moutain out of a mole hill. You are correct it works just as you said.

Thanks
0
 

Expert Comment

by:Member_2_7966052
ID: 41674228
Hi Everyone,

Could we do following CSV file and use the above script to send each email address an email with the left side content... abcd1234 and add123

CSV file content:

abcd1234, abacd@abc.com
add123,     add@add.com

purpose of the above would be the script reads  above CSV file. send email to abacd@abc.com the left hand side content "abacd1234" to "abacd@abc.com" ?

looking forward to hearing from you soon.
0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses
Course of the Month5 days, 21 hours left to enroll

627 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