Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[Tut] Automatic email sending to Email ID!


abhi2011
 Share

Recommended Posts

This is my 4th tutorial and most probs the best one so far. I give credits to GoldSide for actually making one that stores the email ID in account data(though email isn't sent) and to myself.

Required tutorials = http://www.touchofdeathforums.com/smf2/index.php/topic,78011.0.html

if you have done the tutorial please continue.
The email send using gmail's SMTP. How it works is that when the you register there will be a small lag with the server meaning that an email is being sent. (Affects everyone for about 10s.) The server will send an email to the email address specified by the player with the gmail ID the server owner has specified.

SERVER SIDE
Replace the handleNewAccount in modhandle data with
```
Private Sub HandleNewAccount(ByVal Index As Long, ByRef Data() As Byte, ByVal StartAddr As Long, ByVal ExtraVar As Long)
    Dim Buffer As clsBuffer
    Dim Name As String
    Dim Password As String
    Dim Email As String
    Dim i As Long
    Dim n As Long
    Dim oSmtp As New EASendMailObjLib.Mail

    If Not IsPlaying(Index) Then
        If Not IsLoggedIn(Index) Then
            Set Buffer = New clsBuffer
            Buffer.WriteBytes Data()
            ' Get the data
            Name = Buffer.ReadString
            Password = Buffer.ReadString
            Email = Buffer.ReadString

            ' Prevent hacking
            If Len(Trim$(Name)) < 3 Or Len(Trim$(Password)) < 3 Or Len(Trim$(Email)) < 3 Then
                Call AlertMsg(Index, "Your account name must be between 3 and 12 characters long. Your password must be between 3 and 20 characters long.")
                Exit Sub
            End If

            ' Prevent hacking
            If Len(Trim$(Name)) > ACCOUNT_LENGTH Or Len(Trim$(Password)) > NAME_LENGTH Then
                Call AlertMsg(Index, "Your account name must be between 3 and 12 characters long. Your password must be between 3 and 20 characters long.")
                Exit Sub
            End If

            ' Prevent hacking
            For i = 1 To Len(Name)
                n = AscW(Mid$(Name, i, 1))

                If Not isNameLegal(n) Then
                    Call AlertMsg(Index, "Invalid name, only letters, numbers, spaces, and _ allowed in names.")
                    Exit Sub
                End If

            Next

    'send email
            oSmtp.LicenseCode = "TryIt"

    ' Set your Gmail email address
    oSmtp.FromAddr = "[email protected]"

    ' Add recipient email address
    oSmtp.AddRecipientEx Email, 0

    ' Set email subject
    oSmtp.Subject = "Account Creation in " & Options.Game_Name

    ' Set email body
    oSmtp.BodyText = "An account has been recently created in our game " & Options.Game_Name & "." & vbCrLf & "Your login details are," & vbCrLf & "Username = " & Name & vbCrLf & "Password = " & Password & vbCrLf & "If this wasn't you please reply to this email requesting an account delete" & vbCrLf & "Thank You," & vbCrLf & Options.Game_Name & "Staff"

    ' Gmail SMTP server address
    oSmtp.ServerAddr = "smtp.gmail.com"

    ' If you want to use direct SSL 465 port,
    ' Please add this line, otherwise TLS will be used.
    ' oSmtp.ServerPort = 465

    ' detect SSL/TLS automatically
    oSmtp.SSL_init

    ' Gmail user authentication should use your
    ' Gmail email address as the user name.
    ' For example: your email is "[email protected]", then the user should be "[email protected]"
    oSmtp.UserName = "[email protected]"
    oSmtp.Password = "password"

    If oSmtp.SendMail() = 0 Then

          ' Check to see if account already exists
            If Not AccountExist(Name) Then
                Call AddAccount(Index, Name, Password)
                Call TextAdd("Account " & Name & " has been created.")
                Call AddLog("Account " & Name & " has been created.", PLAYER_LOG)

                ' Load the player
                Call LoadPlayer(Index, Name)

                ' Check if character data has been created
                If LenB(Trim$(Player(Index).Name)) > 0 Then
                    ' we have a char!
                    HandleUseChar Index
                Else
                    ' send new char shit
                    If Not IsPlaying(Index) Then
                        Call SendNewCharClasses(Index)
                    End If
                End If

                ' Show the player up on the socket status
                Call AddLog(GetPlayerLogin(Index) & " has logged in from " & GetPlayerIP(Index) & ".", PLAYER_LOG)
                Call TextAdd(GetPlayerLogin(Index) & " has logged in from " & GetPlayerIP(Index) & ".")
            Else
                Call AlertMsg(Index, "Sorry, that account name is already taken!")
            End If

            Set Buffer = Nothing
        End If
    End If
End If

End Sub
```
Then download this file [http://www.emailarchitect.net/webapp/download/easendmail.exe](ftp://www.emailarchitect.net/webapp/download/easendmail.exe)
Then in Menu Bar go to Project > References and find "EASendMailObj ActiveX Object", to add the reference. ![](http://www.emailarchitect.net/img/vb_easendmail.jpg)
Hope you like it and it is tested with my 2 email id's.
Also please replace "[email protected]" & "Passowrd with the appropriate stuff. I also think it will work with email id's given by website hosters as long as it's SMTP.
Link to comment
Share on other sites

@tslusny:

> so do this client side and the wont be any server lag

No I don't think so. But the best way would be to make a packet data sent from server to client telling to do the call the email send. That way would be the best making sure that if registered it will be sent!
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...