Send Email with Credential Already Entered in Batch File

Viewed 180

I would like to send an email with powershell with credentials already entered using a batch file (not a powershell script).

I need this because it is a program where someone could request a feature, but it would use my email to send whatever they put in to myself. I don't want to have to give them my password.

I tried this, but it only works for the username, not the password:

powershell Send-MailMessage -To ansorensen1118@gmail.com -From ansorensen1118@gmail.com  -Subject Testing -Body Testing -Credential (new-object System.Net.NetworkCredential("username","password"))' -SmtpServer smtp.gmail.com -UseSsl
1 Answers

Try to provide the credentials like this:

$Username = 'username'
$Password = 'password'
$pass = ConvertTo-SecureString -AsPlainText $Password -Force
$MySecureCreds = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $Username,$pass
Send-MailMessage ... -Credential $MySecureCreds
Related