Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send mail using Powershell behind a proxy

I'm trying to send an e-mail by using Powershell and GMail, and for now, I managed to do so with this function:

function sendMail{
    $EmailFrom = “[email protected]”
    $EmailTo = “[email protected]”
    $Subject = “Subject”
    $Body = “Hellow”
    $SMTPServer = “smtp.gmail.com”
    $SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587)
    $SMTPClient.EnableSsl = $true
    $SMTPClient.Credentials = New-Object System.Net.NetworkCredential(“username”, “password”);
    $SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body)

    Write-Host "All done!"
}

And this script works just fine if it wasn't the fact we are using a Proxy within our network. How can I modify this function in order to be able to send e-mails in combination with the Proxy.
In other words, how can I connect to the Proxy and send an e-mail by using an external SMTP server.

like image 208
Michiel Avatar asked Dec 04 '12 09:12

Michiel


1 Answers

HTTP and HTTPS proxies don't allow SMTP connections to pass through them.

If you are using a SOCKS proxy, then you can tunnel all your TCP connections through it including SMTP connections which uses TCP.

You can then use WideCap to socksify all the applications or you can use Component pro .Net SMTP client which supports proxy

like image 119
Harshil Lodhi Avatar answered Jan 02 '23 10:01

Harshil Lodhi