send an e-mail with vbs

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gulsh
    New Member
    • Feb 2007
    • 1

    #1

    send an e-mail with vbs

    hello all,

    although i'm not familiar with vbs, i was asked to create a script which will do the following:

    1. change the extension of a document to .txt,
    2. open the file,
    3. read the lines and find an e-mail address,
    4. create a new e-mail with Notes and attach the file,
    5. send it to the e-mail address.


    how much of these can be done with vbs? how can it be done?

    I'd really appreciate your help..
    thanks in advance!

    gulsh
  • willakawill
    Top Contributor
    • Oct 2006
    • 1646

    #2
    Hi the first thing to do is take a look at filesystemobjec t
    Then look for lotus notes automation

    Comment

    • LarsAbildskov
      New Member
      • Feb 2007
      • 1

      #3
      Hi there

      Try this out !

      Put Your mail adresses in a file called 'maillist', and place it in C:\

      The file could look like this:

      john@doe.com
      jane@doe.com



      Then open an empty vbs-file, then copy and paste the lines below ino the file:

      Code:
       'Script start
      Set notessession = CreateObject("Notes.Notessession") 
      Set notesdb = notessession.GetDatabase("", "") 
      Call notesdb.OPENMAIL 
      
      set fso = WScript.CreateObject("Scripting.FileSystemObject") 
      
      ' path1 is Your input file and path2 is the name with the txt extension 
      
        path1 = "C:\maillist" 
        path2 = "C:\maillist.txt" 
      
      ' copy the file 
               fso.CopyFile path1 , path2, true 
               WScript.Sleep 1000 
      
      ' delete Your input file 
               fso.DeleteFile path1 
      
      ' get and open Your mail-address file 
      Set ifile = fso.GetFile("c:\maillist.txt") 
      Set infil = ifile.OpenAsTextStream 
      
      Do until eof 
      ' read a line/mail-address from the file 
              mailadr = infil.readline 
      
      ' if nothing is read, then its EOF, so leave the loop 
              If mailadr = "" then 
                      exit do 
              End if 
      
      'MsgBox (mailadr) 
      
      'Make new mail message 
      Set notesdoc = notesdb.CreateDocument 
      notesdoc.Form = "Memo" 
      
      ' Set up the recipients 
      Call notesdoc.ReplaceItemValue("Sendto", mailadr) 
      'Call notesdoc.ReplaceItemValue("CopyTo", mailadr) 
      'Call notesdoc.ReplaceItemValue("BlindCopyTo", mailadr) 
      
      'The subject of the mail 
      subj = "TEST MAIL  " & mailadr 
      
      
      ' setup three text blocks - note that we use VBCRLF to make the carrige return, line feed 
      mailtxt = "Test mail" 
      
      mailtxt1 = "Hello" & reg 
      
      mailtxt2 = "Here is Your mail" 
      mailtxt2 = mailtxt2 &  VBCRLF 
      mailtxt2 = mailtxt2 &  "Below You will fin a link to google"  & VBCRLF 
      mailtxt2 = mailtxt2 &  VBCRLF 
      mailtxt2 = mailtxt2 &  "Link:" & VBCRLF 
      mailtxt2 = mailtxt2 & "http://www.google.com"  & VBCRLF 
      mailtxt2 = mailtxt2 &  ""  & VBCRLF 
      mailtxt2 = mailtxt2 &  ""  & VBCRLF 
      mailtxt2 = mailtxt2 &  "Regards"  & VBCRLF 
      mailtxt2 = mailtxt2 &  "John Doe"  & VBCRLF 
      
      Call notesdoc.ReplaceItemValue("Subject", subj) 
      Set notesrtf = notesdoc.CreateRichTextItem("body") 
      
      'put the three text blocks in the body of the mail - note that we use AddNewLine to make som space between the blocks 
      Call notesrtf.AppendText(mailtxt) 
      Call notesrtf.AddNewLine(2) 
      
      Call notesrtf.AppendText(mailtxt1) 
      Call notesrtf.AddNewLine(2) 
      
      Call notesrtf.AppendText(mailtxt2) 
      Call notesrtf.AddNewLine(2) 
      
      notesdoc.SaveMessageOnSend = 1 
      
      '  You can also attach a file 
          Call notesrtf.EmbedObject(1454, "", "C:\maillist.txt") 
      
      'Send message 
      notesdoc.PostedDate = Now() 'Gets the mail to appear in the sent items folder 
      Call notesdoc.Send(False) 
      
      loop 
      
      Set fso = Nothing 
      Set notessession = Nothing 
      MsgBox ("Mail send")
      'Script End

      Comment

      Working...