Sending a
mail through the internet is similar to the sending a letter. The major
difference is that the mail delivered through the Internet is delivered
instantly to the desired location. There are many methods of sending Emails.
One can send the Email through the Standard Email client like google, yahoo
etc. or you can use other email clients like MS Outlook etc.
Today I am
going to discuss another method of sending the email using the Powershell. Powershell
is one of the important scripting language which is used for task automation by
the administrators. Using Powershell to send email with attachment is not a
difficult job. Every system administrator should know the command to send email
using Powershell.
Parameters of Send-MailMessage command: -
Send-MailMessage
is the Command that is used in the Powershell to send email with attachment.
Parameters that can be used with the Send –MailMessage are shown bellow.
-To
Enter the Email address to which you want to
send mail.
-Cc string
Enter the Email addresses that you would
like to cc.
-Bcc
Enter the Email addresses that you would
like to bcc.
-From
Email
address from where mail is to be send.
-Subject
Enter the subject of the email message.
-Body
Type your message in the body section
-Attachments
Provide full path of the File to be
attached.
-BodyAsHtml
This
parameter indicates that the body contains the HYML Part.
-Credential
PSCredential
An account that has permission to send the
email. The default is the current user.
-DeliveryNotificationOption
The parameter is used to know the delivery
status of the email.
None – (Default) Indicates No
notification.
OnSuccess – Indicates that the email
has been delivered successfully.
OnFailure – Indicates that the email
has not been delivered
Delay – It will notify if the
delivery is delayed.
Never – It will not give any delivery
notification.
-Encoding
Encoding technique that is used for the body
and the Subject.
-Priority
With thehelp
you can Provide the priority to the email message. Valid values: Low,
Normal (default), High
-SMTP Server
Enter name of the Server in it.
-UseSsl
SSL stands for Secured Soket Layer. Use the
SSL protocol to establish a connection to the SMTP server to send email.
Syntax of Powershell to send email with attachment: -
Send-MailMessage -To “Enter the recipient Email Address” -To”Enter more email address if you require” –cc
”Enter Email address that you would like to CC” – bcc ”Enter Email Address that
you like to Bcc” –From “Enter the
Sender’s Email address” –Subject “Enter the Subject” –Body “ Type your message”
–Attachment $Enter the path of the file –SmtpServer abc.domainname.com
Conclusion: -
The method of
using Powershell to send email with attachment explained in the post will help
you a lot. If you are unable to send Mail using the Powershell please comment
with the error that you are getting we will sort out your query as soon as
possible.
0 comments:
Post a Comment
Post a reply