PoshCode Archive  Artifact [f22dcd42af]

Artifact f22dcd42afe122d5d79cfe499b104b8544b379a93924ff3112a405d67f045a51:

  • File Send-SMSMessage.ps1 — part of check-in [612a86ef34] at 2018-06-10 14:12:08 on branch trunk — http://en.wikipedia.org/wiki/List_of_SMS_gateways (user: dvsbobloblaw size: 3396)

# encoding: ascii
# api: powershell
# title: Send-SMSMessage
# description: http://en.wikipedia.org/wiki/List_of_SMS_gateways
# version: 0.1
# type: script
# author: dvsbobloblaw
# license: CC0
# x-poshcode-id: 6281
# x-archived: 2016-11-18T01:07:19
# x-published: 2016-04-05T14:41:00
# You can send text messages with send-mailmessage. Really easy. I attempted to do something with it, not sure what though.
An attempt to send text messages to phones. 

Have you ever wrote a deamon script that notifies you when a server is down or something else. Wouldn't it be nice to get a TEXT (SMS) message.

Send-TextMessage -Port 587 -SmtpServer 'smtp.gmail.com' -UseSsl -Body 'Hello World' -From 'evilperson@gmail.com' -Subject '>=)' -Number '7238675309' -ServiceProvider Verizon -Credential (Get-Credential)

This will send a text message to 7238675309 from evilperson@gmail.com

This is pretty lame if you already know the person's text email address gateway thing.


    #Specifies the body (content) of the text message.

    #Specifies the address from which the message is sent.

    #Specifies the name of the SMTP server that sends the text message.

    #Specifies the subject of the text message. This parameter is required.

    #Specifies the phone number to which the text message is sent.

    #Specifies a user account that has permission to perform this action. The default is the current user.

    #Uses the Secure Sockets Layer (SSL) protocol to establish a connection to the remote computer to send mail. By default, SSL is not used.

    #Specifies an alternate port on the SMTP server.
    [ValidateRange(0, 2147483647)]

    #Carriers providing Short Message Service (SMS) transit via SMS gateways.

switch ($ServiceProvider) {
    'USCellular' {$Recipient="$Number@email.uscc.net"}
    'Verizon' {$Recipient="$Number@vtext.com"}
    'ATT' {$Recipient="$Number@vmobl.com"}
    'Sprint' {$Recipient="$Number@messaging.sprintpcs.com"}
    'Virgin' {$Recipient="$Number@vmobl.com"}
    'T-Mobile' {$Recipient="$Number@tmomail.net"}
    'Cricket' {$Recipient="$Number@sms.mycricket.com"}
    default {throw 'How did this happen?'}

$Information = @{Body=$Body;From=$From;SmtpServer=$SmtpServer;Subject=$Subject;To=$Recipient;Credential=$Credential;UseSsl=$UseSsl;Port=$Port}

    Send-MailMessage @Information
    throw "Awe, it didn't work."