6600

How to send an email from yahoo SMTP server with PowerShell?

Question:

How to send an email from yahoo SMTP server with PowerShell? Authentication is required.

PowerShell V3

Thanks in advance

Answer1:

<a href="https://technet.microsoft.com/en-us/library/hh849925.aspx" rel="nofollow">Send-MailMessage</a> has a -Credential parameter that takes a pscredential object. I would use a hashtable to store and splat the connection arguments:

$MailArgs = @{ From = 'mindaugas@yahoo.com' To = 'someone@domain.com' Subject = 'A subject line' Body = 'Mail message content goes here!' SmtpServer = 'smtp.mail.yahoo.com' Port = 587 UseSsl = $true Credential = New-Object pscredential 'mindaugas@yahoo.com',$('P@ssW0rd!' |ConvertTo-SecureString -AsPlainText -Force) } Send-MailMessage @MailArgs

Answer2:

in case somebody looking for google smtp using MailMessage

[System.Reflection.Assembly]::LoadWithPartialName("System.Net") [System.Reflection.Assembly]::LoadWithPartialName("System.Net.Mail") [System.Reflection.Assembly]::LoadWithPartialName("System.Net.Mail.MailMessage") $mail = New-Object System.Net.Mail.MailMessage $mail.From = New-Object System.Net.Mail.MailAddress("XXXX@gmail.com"); $mail.To.Add("XXX@XXXX.com"); $mail.Subject = "Place Subject of email here"; $mail.Body = "Place body content here"; $smtp = New-Object System.Net.Mail.SmtpClient("smtp.gmail.com"); $smtp.Port = "587"; $smtp.Credentials = New-Object System.Net.NetworkCredential("XXXXX@gmail.com", "password"); $smtp.EnableSsl = "true"; $smtp.Send($mail);

Recommend

  • How to read text from file into an array in ruby
  • Calling python function with an unknown number of arguments [duplicate]
  • General contract for object comparision : equals() and hashCode()
  • Recursive function not behaving correctly
  • Weird multiplicator operator behavior in a two arrays to hash combination
  • Passing a hashtable from C# to Powershell
  • How dotnet build chooses the output name
  • Why does the font in these TD elements render at different sizes?
  • Python/Javascript: WYSIWYG html editor - Handle large documents fast and/or design theory
  • Getting unread count in Sent Folder using Google Apps Script - GMail
  • How can I make this modal persistent?
  • passing a default argument to a browserify module
  • HttpClient: disabling chunked encoding
  • How to make Twilio api Post request with the help of AFNetworking?
  • Why am I getting a “405 Method not allowed” error on “Put” operations through a WCF Resful service?
  • Why isn't obj.style.left = “200px”; working in this code?
  • hide missing dates from x-axis ggplot2
  • Can't remove headers after they are sent
  • How to convert SOAP response with xsi values to json in WSO2esb
  • Can't delete or rename original file after resizing
  • Check for zero lines output from command over SSH
  • nonblocking BIO_do_connect blocked when there is no internet connected
  • saving file generated by TCPDF
  • Alternative To body {overflow:scroll;} That Will Prevent Page Jostling/Wriggling?
  • Play WS (2.2.1): post/put large request
  • Email verification using google app script and google forms
  • MailKit: The IMAP server replied to the 'EXAMINE' command with a 'BAD' response
  • Illegal mix of collations for operation for date/time comparison
  • MySQL WHERE-condition in procedure ignored
  • Display Images one by one with next and previous functionality
  • Weird JavaScript statement, what does it mean?
  • Do I've to free mysql result after storing it?
  • Warning: Can't call setState (or forceUpdate) on an unmounted component
  • AT Commands to Send SMS not working in Windows 8.1
  • SQL merge duplicate rows and join values that are different
  • Rails 2: use form_for to build a form covering multiple objects of the same class
  • How do I configure my settings file to work with unit tests?
  • Is it possible to post an object from jquery to bottle.py?
  • sending mail using smtp is too slow
  • How to Embed XSL into XML