Solved

Use vbScript to email info from csv file

Posted on 2004-04-05
8
543 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

735 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