0
votes

I have to send an email using a pre-defined account, I have all the information, smtp server name, email address, user, password. This account uses TTL. How to create the script to send this email using VBA. I'm having problems with the Credential parameter, I don't know how to put the username and password

"Send-MailMessage -To 'xxxx@yyy' -from 'kkk@yyyy' -subject 'Teste' -body 'Testando o envio' -stmpserver 'smtp.gmail.com' -UseSSL -Port 587 -Credential (I don't know how to make this parameter) "

1

1 Answers

0
votes

See this SO post how to convert a username-password-pair into a PowerShell credential:

$userName = 'test-domain\test-login'
$password = 'test-password'

$pwdSecureString = ConvertTo-SecureString -Force -AsPlainText $password
$credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $userName, $pwdSecureString

Send-MailMessage -Credential $credential ...

Note: Try to avoid putting passwords into your scripts. Store it somewhere safely, or let the user input it with Read-Host or Get-Credential.