1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

Batch + SendEmail.exe to send email from command line

Discussion in 'Programming' started by Cleptography, Mar 13, 2011.

  1. Cleptography

    Cleptography New Member

    Just a little batch front end for the email command utility SendEmail.exe
    You can get it here:
    http://caspian.dotconf.net/menu/Software/SendEmail/#download

    You will also need colorx.exe which you can get here:
    http://www.westmesatech.com/sst.html

    Optionally you can use Gmail notifier to notify you when you have new unread messages from your system tray.
    Get it here:
    http://toolbar.google.com/gmail-helper/notifier_windows.html

    Script installation instruction:
    1) Create a main directory and call it whatever you want
    2) Create a sub directory inside the main directory called SYSTEM
    3) Put the batch script inside the main directory you created
    4) Put SendEmail.exe and Colorx.exe inside the sub directory SYSTEM
    5) Double click the batch script and fill out all the config file questions.

    NOTES:
    This script will allow you to add and create a contact list which will be shown every time the script is executed.
    Currently there are no attachment options, bcc, ect.. though SendEmail.exe does offer them I did not build them into the script.
    You can modify the script as needed to include these options if you wish.

    SCRIPT:
    Code:
    @echo off
     setlocal
    
    ::######################################################################################################
    ::ScriptName...............: SendMail.bat
    ::Author...................: Cleptography
    ::ScriptPurpose............: Sends email using the SendEmail.exe
    ::Required Files...........: SendEmail.exe(http://caspian.dotconf.net/menu/Software/SendEmail/#download)
    ::                           colorx.exe(http://www.westmesatech.com/sst.html)
    ::Date.....................: 03/04/2011
    ::Time.....................: 13:22:25.13
    ::System Requirements......: N/A
    ::Syntax...................: SendMail.bat
    ::Notes....................: Must have a Gmail account to use
    ::######################################################################################################
    
    REM Set Variables
    set Server=smtp.gmail.com
    set Port=587
    
    REM Check for Config File
    if not exist System\Config cls && call :MakeConfigFile
    cls
    
    :Menu
    REM Menu
    call :Header
    echo.What would you like to do?
    echo.================================================================================
    echo.SendMsg    (Send an Email Message to one of your contacts)
    echo.AddContact (Allows you to add contacts to your email list)
    echo.================================================================================
    
    set /p Ans=?-
    
    if /i "%Ans%"=="SendMsg"    cls && call :SendMessage
    if /i "%Ans%"=="AddContact" cls && call :AddContact
    cls
    goto :Menu
    
    :SendMessage
    call :Header
    REM Grab Variables from Config File
    for /f "tokens=2 delims==" %%a in ('"find /i "Email" "System\Config""') do (
        set MyEmail=%%a
    )
    for /f "tokens=2 delims==" %%a in ('"find /i "Password" "System\Config""') do (
        set MyPassword=%%a
    )
    
    REM Get User Args to Send Mail
    echo.Enter the email address of the recipient.
    echo.================================================================================
    call System\Contacts
    echo.================================================================================
    set /p Recipient=?-
    cls
    
    call :Header
    echo.Enter the subject line of the email?
    echo.================================================================================
    set /p Subject=?-
    cls
    
    call :Header
    echo.Enter the email message?
    echo.================================================================================
    set /p Message=?-
    cls
    
    REM Send Email
    call :Header
    echo.Sending...
    System\SendEmail -f %MyEmail% -t %Recipient% -u "%Subject%" -m "%Message%" -q -s %Server%:%Port% -xu %MyEmail% -xp %MyPassword%
    cls
    call :Header
    echo.Sent!!!
    PAUSE
    cls
    goto :eof
    
    :MakeConfigFile
    call :Header
    echo.Enter your email address.
    echo.================================================================================
    set /p Email=?-
    cls
    
    call :Header
    echo.Enter you email password.
    echo.================================================================================
    set /p Password=?-
    cls
    
    echo.Email=%Email%>>System\Config
    echo.Password=%Password%>>System\Config
    
    goto :eof
    
    :AddContact
    call :Header
    echo.Enter the email address for the new contact.
    echo.================================================================================
    set /p Contact=?-
    echo.echo.%Contact%>>System\Contacts.bat
    goto :eof
    
    :Header
    System\colorx -c c0
    echo.******************************************************************************* 
    System\colorx -c 0c
    echo.   EEEEEEEEEE    MMM        MMM      AAAAAAA      IIIIIIIIIII    LLL
    echo.   EEEEEEEEEE    MMMMM    MMMMM     AAA   AAA     IIIIIIIIIII    LLL
    echo.   EEE           MMM MM  MM MMM    AAA     AAA        III        LLL
    echo.   EEEEEEEE      MMM  MMMM  MMM    AAAAAAAAAAA        III        LLL
    echo.   EEEEEEEE      MMM   MM   MMM    AAAAAAAAAAA        III        LLL
    echo.   EEE           MMM        MMM    AAA     AAA        III        LLL
    echo.   EEEEEEEEEE    MMM        MMM    AAA     AAA    IIIIIIIIIII    LLLLLLLLLLL
    echo.   EEEEEEEEEE    MMM        MMM    AAA     AAA    IIIIIIIIIII    LLLLLLLLLLL    
    System\colorx -c c0
    echo.******************************************************************************* 
    System\colorx -c 0f
    goto :eof
     

Share This Page