Announcement

Collapse
No announcement yet.

Batch File To Replace Contents of a txt File?

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Batch File To Replace Contents of a txt File?

    So I am starting a service that gives out automated texts through an email...I am using Auto Mail Sender. For each message that will be sent, it is required I have a .txt file that fits the needs of the program.

    The thing is, there seems to be nothing in their template that would allow me easy access into the area of the sender...if that makes sense. There is not quotations around who it is to, or anything like that.

    Here is a sample message code that would be sent out:

    Code:
    [email protected], [email protected]
    Subject=Most likely left null in this case
    Attachments=null
    Mail_Type=P
    Content=Message Here
    Priority=N
    One_By_One=N
    Request_Read_Receipt=N
    Schedule=Monthly 23 09:08|Monthly LastDay 15:00|Weekly 5 16:30*30 2|Monthly Fourth 0 09:09*60 1|Specific 2012-06-28 12:00 
    Delete_File_After_Sent=N
    o the thing is, as more people sign up, the 'To' will have to add more and more people. And I do not want to have to change the .txt file for every message every time a new number is registered. Is there a way a masterlist.txt could fill in the 'To" through a .bat file?

  • #2
    Re: Batch File To Replace Contents of a txt File?

    Download gnu sed (gsed) for Windows, free for download!

    Expand the download and copy the 4 files below from sed's 'bin' folder to the batch's folder
    sed.exe
    regex2.dll
    libiconv2.dll
    libintl3.dll

    Now you can use this batch to replace the line starting with "To=" with updated data read from the file "addressees.txt".

    Code:
    @echo off
    
    :: define variables
    Set "InputFile=AutoMailSenderCfgFile.txt"
    Set "OutputFile=tempfile.txt"
    Set "emailTo=addressees.txt"
    
    :: convert unicode- to ansi format
    rem  type "%InputFile%" > "%InputFile%.tmp"
    rem  move /y "%InputFile%.tmp" "%InputFile%"
    
    :: read emailaddresses from file.
    For /F "usebackq tokens=*" %%* in (
       "%emailTo%") Do call :readaddresses %%*
    
    :: Update the line containing the recipients
    "%~0\..\sed.exe" -e "s/^[ ]*To[ ]*=.*$/To=%addressees%/gI" "%InputFile%">"%OutputFile%"
    
    :: enable the next line to actually overwrite(!) the original file with updated data
    rem  move /y "%OutputFile%" "%InputFile%"
    
    
    goto:EOF  begin of sub routine
    :readaddresses
    If defined addressees (
       Set addressees=%addressees%, %*
    ) Else Set addressees=%*
    exit /b 0
    /Rems

    (Similar posts
    http://forums.petri.com/showthread.p...211#post212211
    http://forums.petri.com/showthread.p...230#post253230
    http://forums.petri.com/showthread.p...052#post255052
    http://forums.petri.com/showthread.p...802#post253802

    http://forums.petri.com/showthread.p...225#post253225
    )
    Last edited by Rems; 9th March 2012, 18:59.

    This posting is provided "AS IS" with no warranties, and confers no rights.

    __________________

    ** Remember to give credit where credit's due **
    and leave Reputation Points for meaningful posts

    Comment

    Working...
    X