SwithMail 2.3.0.0
--Send SSL SMTP email silently from command line (CLI), or a batch file using Exchange, Gmail, Hotmail, Yahoo! Plus, or a custom server - for FREE!
Want to see some screen shots?
Swith??
swith (adverb): immediately; quickly.
SwithMail is a Windows application that's extremely easy to use. Run it, fill in the basic settings (from address, to address, SMTP server, subject and body), click save, and you're ready to go. From then on you can send email with those settings silently from the command line, a batch file, a scheduled task, another application or (the reason I wrote it) when a Windows service stops.
SwithMail works with Exchange, Gmail, Hotmail, Yahoo! Plus or any custom SMTP server, with or without SSL/TLS.
Requirements
.NET Framework 4.7.2 or later. It's already included in Windows 10 (version 1803 and later), Windows 11, and Windows Server 2019 and later. On Windows Server 2016 and older systems, install .NET Framework 4.8 from Microsoft first. Without it, SwithMail won't start, and a scheduled task using it will fail.
Tested and working on:
| Desktop | Server |
|---|---|
| Windows 7 SP1 | Windows Server 2008 R2 SP1 |
| Windows 8.1 | Windows Server 2012 / 2012 R2 |
| Windows 10 | Windows Server 2016 |
| Windows 11 | Windows Server 2019 |
| Windows Server 2022 |
Windows 8 (not 8.1) and the original Windows Server 2008 can't run .NET 4.7.2, so use SwithMail 2.2.4.0 there.
Other versions should work, but I haven't tested them. If you try one and it works, let me know and I'll add it to the list.
Usage
SwithMail.exe [/s] [/x "settings.xml"] [/to "..."] [/cc "..."] [/bcc "..."] [/from "..."] [/name "..."]
[/sub "..."] [/b "..."] [/html true] [/a "C:\Path\To\File.txt"]
[/p1 "value"] [/enc "..."] [/rr] [/drnl] [/log "C:\Path\To\Log.txt"] [/priority high]
Example
SwithMail.exe /s /x "C:\path\to\settings.xml" /btxt "C:\path\to\bodyText.txt" /p1 "Mr. Smith" /enc "iso-8859-1"
Notes
- Anything given on the command line overrides the same setting in the XML file. Anything not given uses the XML file's setting.
- Switches aren't case sensitive, and can start with
/,-or--(/sub,-suband--subare the same). - Separate a switch and its value with a space. (
:and=stopped working as separators in 2.0.5.0.)
The easiest way to get the command line right is to set everything up in the settings window: it can generate the command line for you.
Parameters
| Parameter | Short forms | Description |
|---|---|---|
/Silent | /s, /q | Send without showing any window. |
/XML | /x | Path to a settings XML file saved from the settings window. |
/FromAddress | /from | Sender's email address. |
/FromName | /name | Sender's display name. |
/Server | SMTP server address (no port). | |
/Port | /p | SMTP server port. Needed when /Server is used. |
/Username | /u | Username to log in with, if different from the from address. |
/Password | /pass | Password, in plain text. |
/SSL | /TLS | true or false: whether to use SSL/TLS. |
/ToAddress | /to | Recipient address(es). Separate several with ; or ,. |
/CC | CC address(es). Separate several with ; or ,. | |
/BCC | BCC address(es). Separate several with ; or ,. | |
/ReplyTo | /rt | Reply-To address. |
/Subject | /sub | Subject, in quotes. |
/Body | /b | Message body, in quotes. HTML tags are allowed with /HTML true. |
/BodyTxt | /btxt | Full path of a text or HTML file to use as the body. UTF-8 and ANSI files are both supported. |
/HTML | true or false: whether the body is HTML. | |
/Attachment | /a | File(s) to attach, separated by |, e.g. "C:\Path\1.txt|C:\Path\2.txt". Wildcards are supported (see below), and images can be shown inside the body (see Inline images). |
/Param1 – /Param9 | /p1 – /p9 | Replaces %Param1% – %Param9% in the subject, body and from name. |
/Test | For testing from the command line: shows a message with the result. | |
/Encoding | /enc | Character set for the message (UTF-8 by default). |
/ReadReceipt | /rr | Request a read receipt (if the recipient's client agrees). |
/DontReplace | /drnl | Don't turn line breaks into <br /> in HTML email (use this for full .html body files). |
/Log | /l | Path to a log file of successes and failures (date, recipients, subject, attachments). With no path, the log is written to the folder SwithMail runs from. |
/Priority | high or low. Default is normal (no flag). | |
/MessageID | /mid | Generate a Message-ID header. |
Values that start with - or /: these are passed through as values, e.g. /sub "-20% off today". Only SwithMail's own switch names (above) are treated as switches.
Wildcard attachments: "C:\path\to\files\*.csv" attaches every .csv file in that folder. You must give the extension; *.* won't work.
Built-in variables
Use these in the subject, body and from name:
| Variable | Replaced with |
|---|---|
%now% | Current date and time |
%computername% | Computer name |
%username% | Account running SwithMail |
%Param1% – %Param9% | Values of /p1 – /p9 |
Personalized emails
SwithMail.exe /s /to "1@mail.com;2@mail.com" /cc "cc@mail.com" /sub "Here you go, %Param1%" /b "line 1
line 2" /html true /p1 "Mr. Smith"
You don't really need %Param1% when the subject and body are on the command line. Parameters earn their keep with saved settings: open SwithMail, write the subject and body using %Param1% – %Param9%, and save. Then a batch file can call SwithMail once per recipient with a different /to and /p1, and each email is personalized.
Inline images
Attached images can be shown inside an HTML email body instead of as separate attachments. Add the image as an attachment, then refer to it in the body with cid:.
By file name: if the body references an attachment's file name, that file is embedded automatically.
/html true /a "C:\Images\logo.png" /b "<p>Hello!</p><img src=""cid:logo.png"">"
With your own Content-ID: add ? and a name to the end of the attachment path.
/a "C:\Images\logo.png?companylogo" -> <img src="cid:companylogo">
- Only applies to HTML email. In a plain-text email the image is attached normally.
- Images the body doesn't reference are attached normally.
- A
?nameon a wildcard (*) path is ignored, but each matching file can still be embedded by its file name.
Saved passwords
When saving settings to XML you can choose how the password is stored:
| Option | Where it works | Notes |
|---|---|---|
| Plain text | Anywhere | Readable by anyone who opens the file. |
| Obscure PW in XML | Anywhere | Hidden from casual view only. Not real protection. |
| Obscure PW in XML + Lock PW to this computer | Only the computer that saved it | Encrypted with Windows. Any account on that computer can use it, so scheduled tasks running as SYSTEM or a service account keep working. |
If a locked settings file is copied to another computer, sending fails with error code 1 and a log entry saying so. Open the settings on the new computer, re-enter the password and save again. A /pass on the command line overrides the saved password.
Settings files saved by earlier versions keep working unchanged. Locked passwords need version 2.3.0.0 or later.
Using Gmail
Getting "5.5.1 Authentication Required" from Gmail? Google no longer accepts your regular account password from apps like SwithMail. Use an App Password instead:
- Turn on 2-Step Verification for the Google account.
- Create an App Password: Sign in with app passwords.
- Use the 16-character App Password as SwithMail's password, with server
smtp.gmail.com, port587and SSL/TLS on.
(Google's old "Less secure app access" setting has been retired, so that workaround no longer exists.)
Error codes
When running silently, SwithMail exits with:
| Code | Meaning |
|---|---|
0 | Email delivered |
1 | Something went wrong: the email couldn't be sent, or a problem was found before sending (settings file missing or invalid, body file missing, or a locked password from another computer). Nothing is sent in these cases. |
With /log, the reason is written to the log file.
Batch file example
@echo off
C:\SwithMail\SwithMail.exe /s /x "SwithMailSettings.xml"
if %errorlevel% equ 0 (
echo Success!
) else (
echo Error!
)
Known issues
None. All known issues are fixed in the latest release.
Found a bug that isn't listed here? Let me know.
Guide, support and license
- How-to and usage guide (PDF, with screenshots): SwithMail How-To and Usage Guide. Written for version 2.0 (2011), so newer options aren't covered.
- Donate: SwithMail is free for commercial and non-commercial use. If you find it useful, please consider a donation.
- License: SwithMail is licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License.
History
2.3.0.0
New
- Inline images: show attached images inside HTML email using
cid:, either by file name or with a?nameadded to the attachment path. See Inline images. - Lock PW to this computer: optional Windows encryption for saved passwords. See Saved passwords.
- Help text in the settings window for inline images and locked passwords.
Changes
- Now requires .NET Framework 4.7.2 or later (previously 4.6.x). Secure connections now use the newest TLS version Windows supports (including TLS 1.3 where available), instead of being limited to TLS 1.2. See Requirements.
Fixes
- A log path saved in an XML settings file is now used in silent mode (it was ignored).
- Settings XML files are saved as UTF-8, so accented and non-English characters are no longer turned into
?. - Body text files saved as UTF-8 are read correctly (ANSI files still work).
- Silent mode no longer sends an email when the body file or settings file is missing, or the settings file isn't valid. It exits with code 1 and logs why. (An invalid settings file used to leave SwithMail running.)
- Full HTML documents (
<!DOCTYPE html>,<html lang="...">) are no longer wrapped in a second set of<html>/<body>tags. - Values starting with
-or/(e.g./sub "-20% off") are no longer mistaken for switches. Previously they could turn the subject, body or from name into "true". - "Check for updates" compares version numbers correctly (e.g. 2.10 is newer than 2.9) and no longer writes a temporary file.
- Attachment files are released after a failed send, so they're no longer locked after a failed "Test Settings".
- The settings window's "Remember" note now lists
%Param1%–%Param9%.
2.2.4.0
- Enhancement:
%now%,%computername%and%username%can be used in the from name (XML and command line).
2.2.3.0
- Fix: message priority now sets additional headers for different email account types.
- Fix:
%ParamX%is now replaced in a body text file when sending a test email from the settings window (the command line already worked). - Minor fix: relabeled "TSL" to "TLS". The
/tslswitch still works for older scripts. - Tweak: rearranged the main window to make it slightly smaller.
2.2.2.0
- Fix: Reply-To issue resolved.
2.2.1.0
- Enhancement: increased the number of parameters from 5 to 9.
- Minor bug fixes.
2.2.0.0
- Updated to .NET Framework 4.6.2.
2.1.9.0
- Enhancement: added "Generate Message-ID".
- Tweak: updated the donation link.
2.1.8.0
- Enhancement: CC, BCC and attachments are included in the log file.
2.1.7.0
- Enhancement: added
/Logand/Priority.
2.1.6.0
- Fix: Outlook no longer replaces attachment extensions with
.dat.
2.1.5.0
- Fix: wildcard attachments no longer ignore the text before the asterisk.
2.1.4.0
- Enhancement: option to not replace new lines with
<br />in HTML email (for.htmlbody files). - Enhancement: added a plain-text version to HTML emails to help reduce spam scores.
2.1.3.0
- Enhancement: wildcard attachments, e.g.
"C:\path\to\files\*.csv"attaches all.csvfiles in the folder. The extension is required;*.*won't work.
2.1.2.0
- Enhancement: added
/ReadReceipt(/rr).
2.1.1.1
- Fix: encoding issues with non-US characters in ANSI body text files.
2.1.1.0
- Enhancement: added
/Encoding(/enc). - Enhancement: settings window can select a body text file and set the encoding.
- Enhancement: XML settings store the body text file and encoding.
2.1.0.0
- Enhancement: added
/BodyTxt(/btxt): use a text file as the message body.%Param1%–%Param5%are replaced in the file.
2.0.9.0
- Enhancement: exit codes (
0success,1error) for batch files.
2.0.8.0
- Fix: hang when running as a scheduled task under a different user.
2.0.7.0
- Added a "Username" field, for logging in with a username other than the from address.
2.0.6.0
- Added a "Reply To" field.
2.0.5.0
- Removed
:and=as argument separators. They caused problems when those characters appeared in values.
2.0.4.0
- Fix:
/subchanging to "true" when using the long command-line form.
2.0.3.0
- Added the option to obscure the password in the XML file.
2.0.2.0
- Added the built-in variables
%now%,%computername%and%username%.
2.0.1.0
- Fix: the generated command line no longer clears from the clipboard when the program closes.
2.0 (changes from 1.5)
- Settings are saved to an XML file instead of inside the app, and the XML file is given on the command line.
- Multiple attachments: up to 4 in the settings window, unlimited* in XML and on the command line.
- The settings window can generate the command line for you.
- Easier-to-read usage screen.
- Tab-based settings window: smaller, with room for more settings.
- Several other minor tweaks and enhancements.
* SwithMail will try to deliver every attachment, but email providers may have size or count limits. If a limit is exceeded, the email may fail to send.
Typical disclaimer applies:
This software is provided by the copyright holder and contributors "as is" and any express or implied warranties, including, but not limited to, the implied warranties of merchantability and fitness for a particular purpose are disclaimed. In no event shall the copyright owner or contributors be liable for any direct, indirect, incidental, special, exemplary, or consequential damages (including, but not limited to, procurement of substitute goods or services; loss of use, data, or profits; or business interruption) however caused and on any theory of liability, whether in contract, strict liability, or tort (including negligence or otherwise) arising in any way out of the use of this software, even if advised of the possibility of such damage.
Basically, I am not responsible for the way this application is used, nor can I ensure that no damage will be caused by using this program. Don't use it to send SPAM. Please... that's not why I wrote it, and nobody likes SPAM!

