Imports System.Web Imports System.Web.Services Imports System.Web.Services.Protocols ' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. ' _ _ _ _ Public Class Service Inherits System.Web.Services.WebService Public Enum ServiceName Cingular ATT Verizon VirginMobile Nextel MetroPCS TMobile SprintPCS Unknown End Enum _ Public Function SendSMSEnum(ByVal toPhoneNumber As String, ByVal toService As ServiceName, ByVal theMessage As String) As ReturnResults Return sendSMSInternal(toPhoneNumber, toService, theMessage) 'we redirect the variables to the internal function. This is so we can have 2 entry points to this function 'The SMSEnum one is used if you are passing the ServiceName Enum to it. End Function _ Public Function SendSMSString(ByVal toPhoneNumber As String, ByVal toService As String, ByVal theMessage As String) As ReturnResults 'we redirect the variables to the internal function. This is so we can have 2 entry points to this function 'The SMSString one is used if you are passing the string to it, usefull for debugging. Dim theserviceprovider As ServiceName 'Convert the text they gave us to the enum Select Case toService.ToLower Case "att" theserviceprovider = ServiceName.ATT Case "cingular" theserviceprovider = ServiceName.Cingular Case "verizon" theserviceprovider = ServiceName.Verizon Case "tmobile" theserviceprovider = ServiceName.TMobile Case "virginmobile" theserviceprovider = ServiceName.VirginMobile Case "sprintpcs" theserviceprovider = ServiceName.SprintPCS Case "nextel" theserviceprovider = ServiceName.Nextel Case "metropcs" theserviceprovider = ServiceName.MetroPCS Case Else 'teleflip is another service that handles sms gateways, they go a step further and do a lookup on the phone number 'to the provider. theserviceprovider = "teleflip.com" End Select Return sendSMSInternal(toPhoneNumber, theserviceprovider, theMessage) End Function Function sendSMSInternal(ByVal toPhoneNumber As String, ByVal toService As ServiceName, ByVal theMessage As String) As ReturnResults Dim TheResults As ReturnResults = New ReturnResults 'This is where you can define the limit of how often they can send sms's. By default it is 1 per minute. 'You can set this to just the current hour, to allow 1 per hour, or to the current day to allow 1 per day, etc. Dim Comparetimenow As String = System.DateTime.Now.Hour & ":" & System.DateTime.Now.Minute Try If IsNothing(Context.Session("lastsendtime")) = False Then If Context.Session("lastsendtime") = Context.Session("lastsendtime") = Comparetimenow Then TheResults.DidItWork = False TheResults.ReturnMessage = "You are sending too fast, message has been blocked." Return TheResults Exit Function End If End If Catch ex As Exception 'This is their first run, so do nothing End Try 'Set the 'lastsendtime' variable so that people can only send within the limit Try Context.Session("lastsendtime") = Comparetimenow Catch ex As Exception End Try Dim theserviceprovider As String = "" Select Case toService Case ServiceName.ATT theserviceprovider = "mms.att.net" Case ServiceName.Cingular theserviceprovider = "cingularme.com" Case ServiceName.Verizon theserviceprovider = "vtext.com" Case ServiceName.TMobile theserviceprovider = "tmomail.net" Case ServiceName.VirginMobile theserviceprovider = "vmobl.com" Case ServiceName.SprintPCS theserviceprovider = "messaging.sprintpcs.com" Case ServiceName.Nextel theserviceprovider = "messaging.nextel.com" Case ServiceName.MetroPCS theserviceprovider = "mymetropcs.com" Case Else 'teleflip is another service that handles sms gateways, they go a step further and do a lookup on the phone number 'to the provider. You are drastically limited to how many you can send per day. theserviceprovider = "teleflip.com" End Select If toPhoneNumber <> "" Then 'clean up the myriad of different ways people can enter a number toPhoneNumber = toPhoneNumber.Replace("-", "").Replace(" ", "").Replace("/", "").Replace("\", "").Replace("(", "").Replace(")", "").Replace(".", "") If Left(toPhoneNumber, 1) = "1" Then toPhoneNumber = toPhoneNumber.Substring(2) If IsNumeric(toPhoneNumber) = True And Len(toPhoneNumber) = 10 Then TheResults = sendemail(toPhoneNumber & "@" & theserviceprovider, "sms@madmasterminds.com", "SMS", theMessage & vbCrLf & vbCrLf & vbCrLf & vbCrLf & "Message relayed for free through http://web2sms.MadMasterMinds.com.") Else toPhoneNumber = "Invalid" TheResults.DidItWork = False TheResults.ReturnMessage = "Invalid Phone Number" End If Else toPhoneNumber = "Invalid" TheResults.DidItWork = False TheResults.ReturnMessage = "Invalid Phone Number" End If Return TheResults End Function Function sendemail(ByVal towho As String, ByVal fromwho As String, ByVal subject As String, ByVal message As String) As ReturnResults Dim theresults As ReturnResults = New ReturnResults Try Dim MailObj As New System.Net.Mail.SmtpClient 'Create the mail object Dim mymail As New System.Net.Mail.MailMessage 'Create the email object we will be sending Dim thesender As New System.Net.Mail.MailAddress(fromwho) ' Create the from address MailObj.Host = "localhost" 'This is your mail server, for example mail.gmail.com 'Use this if your mail server requires authentication" MailObj.Credentials = New System.Net.NetworkCredential("EMAILACCOUNT", "EMAILPW") 'Use This if you DONT need authentication 'MailObj.UseDefaultCredentials = True MailObj.UseDefaultCredentials = false mymail.IsBodyHtml = True 'Make it a html formatted message mymail.To.Add(towho) 'Send to who mymail.To.Add("sms@madmasterminds.com") 'Send to who mymail.From = thesender : mymail.Sender = thesender ' Set the from address From = Email, sender can include a name mymail.Subject = subject 'Subject mymail.Body = message 'Message MailObj.Send(mymail) 'Send the email mymail.Dispose() theresults.DidItWork = True theresults.ReturnMessage = "Message sent." Catch ex As Exception theresults.DidItWork = False theresults.ReturnMessage = "Message send failed, mail error.

" & ex.Message End Try Return theresults End Function Partial Class ReturnResults 'This is the class we send back to show if it passed or not, as well as give information if it failed. Public DidItWork As Boolean Public ReturnMessage As String End Class End Class