Wednesday, 19 March 2014

Send mail Using PowerShell

There are couple of ways to send mail using PowerShell cmdLet.
I generally use these cmdLet to verify outgoing email settings.

  1.  Using smtp address (Hardcoding the SMTP address)

function send-notification($subject, $detail) {
    $message = New-Object System.Net.Mail.MailMessage
    $message.Subject = $subject
    $message.Body = $detail
    $message.From = "" # we can use sent From as $headers.Add("from", "") also
    $client = New-Object System.Net.Mail.SMTPClient -ArgumentList ""  

$dbname = Get-SPContentDatabase -WebApplication http://servername:port
send-notification -subject "$dbname Attached" -detail "The content database $dbname has completed the database attach upgrade. Please review the logs in Central Administration as soon as possible."

2. Using Microsoft.SharePoint.Utilities.SPUtility
$web = Get-SPWeb -Site http://q3gn0470:2222
$headers = New-Object System.Collections.Specialized.StringDictionary
        $headers.Add("to", "")
        $headers.Add("to", "")
        $headers.Add("cc", "")      
        $headers.Add("bcc", "")      
        $headers.Add("from", "")
        $headers.Add("subject", "Test Email Subject")
        $headers.Add("content-type", "text/html")
        $bodyText = "Hello how are you?"
        [Microsoft.SharePoint.Utilities.SPUtility]::SendEmail($web, $headers, $bodyText)


  1. I was wondering if you ever thought of changing the page layout of your site?
    Its very well written; I love what youve got to
    say. But maybe you could a little more in the way of content
    so people could connect with it better. Youve got an awful
    lot of text for only having 1 or 2 pictures.
    Maybe you could space it out better?

    Here is my page: slow pitch

  2. This piece of writing will assist the internet viewers for creating new weblog or even a weblog from start to end.

    Visit my web blog - stamped concrete ma

  3. Hi! I realize this is kind of off-topic however I had to ask.
    Does building a well-established blog like yours
    require a massive amount work? I am completely new to writing a blog but I do write in my diary daily.

    I'd like to start a blog so I can share my experience and feelings online.
    Please let me know if you have any recommendations or tips
    for new aspiring blog owners. Thankyou!

    Feel free to surf to my homepage ... citywide home loans reviews denver