如何在Windows上编译带SMTP支持的CURL?解决SMTP协议不支持报错
Let's break down exactly how to compile curl with SMTP support (alongside basic file download protocols like HTTP) without including SSL or SSH. The error you're seeing means your current build didn't enable SMTP support—even if you used Visual Studio, the default settings probably didn't flip that critical switch.
Step 1: Grab the Latest Curl Source Code
First, download the full curl source code and extract it to a folder on your machine (e.g., C:\curl-source). Pre-built binaries won't work here since we need a customized build.
Step 2: Configure the Build for SMTP (No SSL/SSH)
Curl has a dedicated Windows build system via its winbuild scripts, which is far more reliable than manually tweaking Visual Studio project settings. Here's how to use it:
- Open a Visual Studio Command Prompt matching your target architecture (x86, x64, etc.—you'll find this in the Visual Studio "Tools" folder in the Start Menu).
- Navigate to the winbuild directory in your source folder:
cd C:\curl-source\winbuild - Run this
nmakecommand to enable only the features you need:
Let's unpack the flags:nmake /f Makefile.vc mode=static WITH_SMTP=yes WITHOUT_SSL=yes WITHOUT_SSH=yes PROTOCOLS="http smtp"mode=static: Builds a static library (swap tomode=dllif you prefer a dynamic link library)WITH_SMTP=yes: Enables SMTP protocol support explicitlyWITHOUT_SSL=yes: Disables all SSL-related dependencies (since you don't need them)WITHOUT_SSH=yes: Turns off SSH/SCP/SFTP supportPROTOCOLS="http smtp": Restricts the build to only HTTP (for file downloads) and SMTP (for email sending) to keep it lightweight.
Step 3: Locate the Compiled Binary
Once the build finishes successfully, your custom curl.exe will be in the builds subfolder of your source directory. For example, a 64-bit static release build would live at:
C:\curl-source\builds\libcurl-vc-x64-static-release\bin\curl.exe
Step 4: Verify the Build
Test your new binary to confirm SMTP is enabled:
- Open a regular command prompt, navigate to the folder containing your new
curl.exe - Run:
Look for the "Protocols" line—it should explicitly listcurl --versionhttpandsmtp. If it does, you're ready to send emails and download files without that error.
Troubleshooting Quick Fixes
- Missing build tools? Ensure you're using the Visual Studio Command Prompt (not a regular cmd window)—it sets up all necessary environment variables for compiling.
- SMTP still not listed? Double-check your
nmakecommand for typos—did you includeWITH_SMTP=yesand addsmtpto thePROTOCOLSflag? - Need a DLL instead? Swap
mode=statictomode=dllin thenmakecommand.
内容的提问来源于stack exchange,提问作者J. Doe Junior

