$ss = new-object Security.SecureString foreach ($ch in "password".ToCharArray()) { $ss.AppendChar($ch) } $cred = new-object Management.Automation.PSCredential "uid@domain.com", $ss Send-MailMessage -SmtpServer smtp.gmail.com -UseSsl -Credential $cred -Body... Send-MailMessage : The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at At foo.ps1:18 char:21 + Send-MailMessage <<<< ` + CategoryInfo : InvalidOperation: (System.Net.Mail.SmtpClient:SmtpClient) [Send-MailMessage], SmtpException + FullyQualifiedErrorId : SmtpException,Microsoft.PowerShell.Commands.SendMailMessage $EmailFrom = "notifications@somedomain.com" $EmailTo = "me@earth.com" $Subject = "Notification from XYZ" $Body = "this is a notification from XYZ Notifications.." $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) $smtpClient = new-object system.net.mail.smtpClient $smtpClient.Host = 'smtp.gmail.com' $smtpClient.Port = 587 $smtpClient.EnableSsl = $true $smtpClient.Credentials = [Net.NetworkCredential](Get-Credential GmailUserID) $smtpClient.Send('GmailUserID@gmail.com','yourself@somewhere.com','test subject', 'test message') # append to Christian's code above --^ $emailMessage = New-Object System.Net.Mail.MailMessage $emailMessage.From = $EmailFrom $emailMessage.To.Add($EmailTo) $emailMessage.Subject = $Subject $emailMessage.Body = $Body $emailMessage.Attachments.Add("C:Test.txt") $SMTPClient.Send($emailMessage) ## Send-Gmail.ps1 - Send a gmail message ## By Rodney Fisk - xizdaqrian@gmail.com ## 2 / 13 / 2011 # Get command line arguments to fill in the fields # Must be the first statement in the script param( [Parameter(Mandatory = $true, Position = 0, ValueFromPipelineByPropertyName = $true)] [Alias('From')] # This is the name of the parameter e.g. -From user@mail.com [String]$EmailFrom, # This is the value [Don't forget the comma at the end!] [Parameter(Mandatory = $true, Position = 1, ValueFromPipelineByPropertyName = $true)] [Alias('To')] [String[]]$Arry_EmailTo, [Parameter(Mandatory = $true, Position = 2, ValueFromPipelineByPropertyName = $true)] [Alias( 'Subj' )] [String]$EmailSubj, [Parameter(Mandatory = $true, Position = 3, ValueFromPipelineByPropertyName = $true)] [Alias( 'Body' )] [String]$EmailBody, [Parameter(Mandatory = $false, Position = 4, ValueFromPipelineByPropertyName = $true)] [Alias( 'Attachment' )] [String[]]$Arry_EmailAttachments ) # From Christian @ StackOverflow.com $SMTPServer = "smtp.gmail.com" $SMTPClient = New-Object Net.Mail.SMTPClient( $SmtpServer, 587 ) $SMTPClient.EnableSSL = $true $SMTPClient.Credentials = New-Object System.Net.NetworkCredential( "GMAIL_USERNAME", "GMAIL_PASSWORD" ); # From Core @ StackOverflow.com $emailMessage = New-Object System.Net.Mail.MailMessage $emailMessage.From = $EmailFrom foreach ( $recipient in $Arry_EmailTo ) { $emailMessage.To.Add( $recipient ) } $emailMessage.Subject = $EmailSubj $emailMessage.Body = $EmailBody # Do we have any attachments? # If yes, then add them, if not, do nothing if ( $Arry_EmailAttachments.Count -ne $NULL ) { $emailMessage.Attachments.Add() } $SMTPClient.Send( $emailMessage ) $smtpmail = [System.Net.Mail.SMTPClient]("127.0.0.1") $smtpmail.Send("myacct@gmail.com", "myacct@gmail.com", "Test Message", "Message via local smtp") $filename = “c:scripts_scotttest9999.xls” $smtpserver = “smtp.gmail.com” $msg = new-object Net.Mail.MailMessage $att = new-object Net.Mail.Attachment($filename) $smtp = new-object Net.Mail.SmtpClient($smtpServer ) $smtp.EnableSsl = $True $smtp.Credentials = New-Object System.Net.NetworkCredential(“username”, “password_here”); # Put username without the @GMAIL.com or – @gmail.com $msg.From = “username@gmail.com” $msg.To.Add(”boss@job.com”) $msg.Subject = “Monthly Report” $msg.Body = “Good MorningATTACHED” $msg.Attachments.Add($att) $smtp.Send($msg)