PowerShell批量发送主动求职邮件时SMTP认证错误问题咨询
Hey there, sorry to hear you're stuck with this SMTP authentication error while trying to send out your job outreach emails—job hunting is already tough enough without technical roadblocks slowing you down! Let’s walk through the most likely causes and fixes for that 5.7.57 error.
Common Reasons & Solutions
- Missing secure connection requirement: The error message explicitly mentions the server needs a secure connection, which is super common for modern email providers. Most SMTP servers (like Gmail, Outlook, Yahoo) force SSL/TLS encryption now. If your PowerShell script isn’t enabling this, it’ll fail authentication. Make sure to add the
-UseSslparameter when callingSend-MailMessage, and double-check you’re using the correct port for encrypted connections (e.g., 587 for TLS, 465 for SSL). - Incorrect SMTP server or port: Different email services use unique SMTP settings. For example:
- Gmail:
smtp.gmail.comon port 587 (TLS) - Outlook/Office 365:
smtp.office365.comon port 587 (TLS) - Yahoo:
smtp.mail.yahoo.comon port 587 (TLS)
If you used the wrong server address or port, even with the right credentials, the server will reject your unencrypted/incorrect connection.
- Gmail:
- Credential formatting issues: Even if you’re sure your password is right, some providers require the full email address as the username (not just the part before the @). Also, avoid hardcoding credentials directly in the script—use
Get-Credentialto prompt for them, which reduces the chance of typos. - Gmail-specific considerations: If you switch to Gmail, keep in mind:
- If you have 2-Step Verification enabled on your account, you’ll need to create an App Password instead of using your regular account password.
- Gmail has strict limits on outgoing emails (500 per day for regular accounts), so make sure you stay under that to avoid getting your account flagged.
Example Working Script Snippet
Here’s a quick test script that includes all the necessary secure settings for Gmail:
# Configure your settings $smtpServer = "smtp.gmail.com" $smtpPort = 587 $senderEmail = "your.full.email@gmail.com" $subject = "Inquiry Regarding Potential Job Opportunities" $body = @" Hi [Hiring Manager], [Your standard outreach message here] Best regards, [Your Name] "@ # Get credentials securely $credential = Get-Credential -Message "Enter your Gmail credentials (use full email as username)" # List of recipient emails (you could load this from a CSV too!) $recipients = @("company1@example.com", "company2@example.com") # Send emails in a loop foreach ($recipient in $recipients) { Send-MailMessage -From $senderEmail -To $recipient -Subject $subject -Body $body ` -SmtpServer $smtpServer -Port $smtpPort -UseSsl -Credential $credential ` -DeliveryNotificationOption OnFailure }
Start by verifying your SMTP server settings match your email provider’s official specs, then add the -UseSsl parameter and correct port. If that doesn’t work, double-check your credential format or consider switching to Gmail with the app password setup if your current provider’s settings are giving you too much trouble.
备注:内容来源于stack exchange,提问作者Paco 2015

