Send WordPress posts from the command-line by email

Sending textfiles and images as post to WordPress by email 

  • Have *.txt files in a directory per category.
  • The name of the txt-file is the post subject
  • Add an image with the same name for a featured image.
  • Works on any windows machine.
  • Category is sent in the subject in this form:  [CategoryName] Subject

 

  1. setup an smtp/pop3 email account:
    in this example: wp12345@email.com
    make sure you create a hard to guess email box to avoid spam.
  2. install postie plugin and configure
  3. download blat
  4. create a wp-post.cmd file as follows, and adjust to your situation:
    @echo off
    
    FOR %%f IN (E:\Users\Rob\Stack\ufootje.nl\wordpress\postbyemail\categories\BikeTrips\*.txt) DO ( call :postfile2wp "%%f" )
    goto end
    
    :postfile2wp
    set Folder=%~dp1
    set Filename=%~nx1
    set Descr=%~n1
    set ImgFile="%Folder%%Descr%.jpg"
    if exist %ImgFile% ( call :postfilewithimage %1 "[BikeTrips] %Descr%" %ImgFile%) else ( call :postfile %1 "[BikeTrips] %Descr%" ) 
    EXIT /B
    
    :postfile
    c:\tools\blat.exe %1 -subject %2 -to wp12345@email.com -server smtp.email.com -u your@email.com -pw mypassword -f your@email.com 
    exit /b
    
    :postfilewithimage
    c:\tools\blat.exe %1 -subject %2 -attach %3 -to wp12345@email.com -server smtp.email.com -u your@email.com -pw mypassword -f your@email.com 
    exit /b
    
    
    :end
    pause