Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

Sending an Email from code, safer

Avatar of zipnotic
zipnoticFlag for United States of America asked on
Programming.NET Programming
10 Comments1 Solution313 ViewsLast Modified:
Hello,

I've been using the below code to send myself an email when the user registers my application in the field.  It grabs the WAN IP along with the computer name.  The application is free but I've been thinking of charging a low fee for each copy.  Obviously this isn't the best way (putting my account name and password in code) but it is free, simple, and it works.  I'd like to make it a little more secure without costing anything for server space, third party DLLs, etc.  I was looking at some older methods of sending an email direct without logging into gmail account but I couldn't make it work.  Obfuscation doesn't seem like much resilience if someone were to decompile the code.  It's written in VB.Net.  Any ideas?

Current Code:

If Me.txtEmail.Text = "" Or Me.txtAgency.Text = "" Or Me.txtName.Text = "" Then
            MsgBox("Required field left blank.", MsgBoxStyle.Critical, "Error.")
            Exit Sub
        End If


        Try
            eBody = (New WebClient()).DownloadString("http://checkip.dyndns.org/")
            eBody = "IP:" & (New System.Text.RegularExpressions.Regex("\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}")).Matches(eBody)(0).ToString()
            Me.txtWAN.Text = eBody
            eBody += vbCrLf
            Application.DoEvents()
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try

        Try
            eBody += "Com Name:" & My.Computer.Name
            Me.txtPCName.Text = My.Computer.Name
            eBody += vbCrLf
            Application.DoEvents()
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try


        Try
            eBody += "Date: " & Now() & vbCrLf
            eBody += "Name: " & Me.txtName.Text & vbCrLf
            eBody += "Email: " & Me.txtEmail.Text & vbCrLf
            eBody += "Organization: " & Me.txtOrganization.Text & vbCrLf
            eBody += "Comments: " & Me.txtComments.Text & vbCrLf

        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try

        Try
            Dim Smtp_Server As New SmtpClient
            Dim e_mail As New MailMessage()
            Smtp_Server.UseDefaultCredentials = False
            Smtp_Server.Credentials = New NetworkCredential("MyThrowawayGmailAccount@gmail.com", "someobscurepassword")
            Smtp_Server.Port = 587
            Smtp_Server.EnableSsl = True
            Smtp_Server.Host = "smtp.gmail.com"
            e_mail = New MailMessage()
            e_mail.From = New MailAddress("MyThrowawayGmailAccount@gmail.com")
            e_mail.To.Add("myactualgmailaccount@gmail.com")
            e_mail.Subject = "Application Registration " & Now()
            e_mail.IsBodyHtml = False


            eBody = Encrypt(eBody, "encryptionpassword", “encryptionsalt", "SHA1", 3, "somestringhere", 256)
            e_mail.Body = eBody
            Smtp_Server.Send(e_mail)


            Try
                If File.Exists(Application.StartupPath & "\registrationKey.txt") Then
                    File.Delete(Application.StartupPath & "\registrationKey.txt")
                End If

                Using outfile As StreamWriter = File.AppendText(Application.StartupPath & "\RegistrationKey.txt")

                    outfile.Write(eBody)
                    outfile.Close()
                End Using
                ' File.Encrypt(Application.StartupPath & "\RegistrationKey.txt")
            Catch ex As Exception

            End Try
        Catch error_t As Exception
            MsgBox(error_t.ToString)
        End Try

        MsgBox("Registration Complete!", MsgBoxStyle.Exclamation, "Thank You")
        Me.Close()

    End Sub
ASKER CERTIFIED SOLUTION
Avatar of MlandaT
MlandaTFlag of South Africa image

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Commented:
This problem has been solved!
Unlock 1 Answer and 10 Comments.
See Answers