You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Git Bash执行邮件脚本报错'mail: command not found',求HTML邮件发送方案

Fixing 'mail: command not found' and Sending HTML Emails in Git Bash

Hey there! That "mail: command not found" error pops up because Git Bash doesn’t include the standard Unix mail tool out of the box. But don’t worry—we’ve got two solid ways to get your HTML emails sent from Git Bash:

Option 1: Use Windows PowerShell (No Extra Installs Needed)

Git Bash can directly call Windows tools, and PowerShell has a built-in Send-MailMessage cmdlet that handles HTML emails perfectly. Here’s a ready-to-use command you can tweak:

powershell.exe -Command "Send-MailMessage -From 'your-email@example.com' -To 'dineshl@gmail.com' -Subject 'This is the subject' -Body '<h1>Your HTML Message Goes Here</h1><p>With paragraphs and other tags!</p>' -BodyAsHtml -SmtpServer 'smtp.example.com' -Port 587 -UseSsl -Credential (Get-Credential)"

A few key notes to make this work:

  • Replace smtp.example.com with your email provider’s SMTP server (e.g., smtp.gmail.com for Gmail).
  • If you’re using Gmail with 2FA enabled, you’ll need to use an App Password instead of your regular account password.
  • The -Credential (Get-Credential) part will prompt you for your email password—avoid hardcoding plaintext passwords in scripts; use secure credential storage for automation.

Option 2: Install the mail Utility via Pacman

Git Bash is built on MSYS2, so you can use the pacman package manager to install the missing mail tool:

  1. First, update the package list in Git Bash:

    pacman -Sy
    
  2. Install the mailutils package (which includes the mail command):

    pacman -S mailutils
    
  3. Configure your SMTP settings by editing the /etc/mail.rc file. Open it with nano:

    nano /etc/mail.rc
    

    Add these lines (replace placeholders with your email details):

    set smtp=smtp://smtp.example.com:587
    set smtp-auth=login
    set smtp-auth-user=your-email@example.com
    set smtp-auth-password=your-app-password-or-password
    set ssl-verify=ignore
    set nss-config-dir=/etc/pki/nssdb/
    

    Save and exit (in nano, press Ctrl+O, hit Enter, then Ctrl+X).

  4. Now you can use a modified version of your original script to send HTML emails:

    echo "<h1>HTML Message goes here</h1>" | mail -s "$(echo -e 'This is the subject\nContent-Type: text/html')" dineshl@gmail.com
    

Critical Security Reminder

Never hardcode your email password directly in scripts or configuration files. For automated workflows, use environment variables or encrypted credential storage instead.

内容的提问来源于stack exchange,提问作者Dinesh

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 08:21:27