Example 1
Send-MailMessage -From 'john<john@abc.com>' -To 'raj<raj@techieseek.com>' -Subject 'breaking news'
Example 2: Send an attachment
Send-MailMessage -From 'john<john@abc.com>' -To 'raj<raj@techieseek.com>' -Subject 'breaking news' -Body "sending the attachment" -Attachments .\data.csv -Priority High -Smthttps://techdiip.com/wp-admin/post-new.php#pServer 'smtp.abc.com'Parameters Explained. Attachments<String[]> We have to specify the path of the attachment and file name. Bcc<String[]> This parameter is used for Email addresses that receive a copy of an email message but does not appear as a recipient. Body <String_>This parameter is used for writing the Content of the email message BodyAsHtml It indicates that the content is in HTML format. Cc<String[]>This parameter used for sending CC Email addresses that receive a copy of an email message Credential This parameter is used for Specifying a user account that has permission to send message from a specified email address. DeliveryNotificationOption From This parameter used for Email addresses from which the mail is sent Port: This parameter is used for specifying the Alternate port on the SMTP server. Priority This parameter is used for defining the priority of the email message. Acceptable values: Normal, High, Low. SmtpServer This parameter is used for specifying the Name of the SMTP server that sends the email message. Subject This parameter used for specifying the Subject of the email message. To: This parameter used for specifying Email addresses to which the mail is sent. UseSsl This parameter Uses the Secure Sockets Layer (SSL) protocol to establish a connection to the remote computer to send mail DeliveryNotificationOption: Specifies the delivery notification options for the email message. Multiple values can be specified. You can specify multiple values. The acceptable values for this parameter are as follows: None: This option for No notification. OnSuccess: This option to Notify if the delivery is successful. OnFailure: This option to Notify if the delivery is unsuccessful. Delay: This option to Notify if the delivery is delayed. Never: This option for Never notify. Encoding This parameter is used for Specifying the type of encoding for the target file and the acceptable values for this parameter are as follows: ASCII, BigEndianUnicode, OEM, Unicode, UTF7, UTF8, UTF8BOM, UTF8NoBOM and UTF32. How to send text file data as email body text using Powershell script.
$businesstxt_File = "c:\businessnews.txt" function Send_textfile_mail { #specifying the Email settings $EmailFrom = "raja@abc.com" $EmailTo = "techierun@abc.com" $Txt_Body = Get-Content $businesstxt_File -RAW $Body = $Body_Custom + $Txt_Body $Subject = "Business text file" $SMTPServer = "smtpserver.domain.com" $SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 25) $SMTPClient.EnableSsl = $false $SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body) } $Body_Custom = "Please see the business text file information : " #calling the function to work! Send_textfile_mailHere are the are top SMTP email providers SMTP addresses and these will be useful when you want to try out Powershell script using a free hosting provider.
The Email Service Provider Name |
Name of the SMTP server |
Port Number |
Connection |
Gmail |
smtp.gmail.com |
587 |
TLS |
25 |
TLS |
||
|
465 |
SSL |
|
Outlook.com |
smtp-mail.outlook.com |
587 |
TLS |
25 |
|||
Office 365 |
smtp.office365.com |
587 |
TLS |
25 |
|||
Windows Live Hotmail |
smtp.live.com |
587 |
TLS |
25 |
|||
465 |
SSL |
||
Yahoo mail |
smtp.mail.yahoo.com |
587 |
TLS |
25 | TLS |
Leave a Reply Cancel reply