locked
How do I send a verification email on button click? RRS feed

  • Question

  • Hi, I need to be able to send a verification email to a user of my program when he/she clicks a button. The user puts his/her email in a textbox and clicks a signup button that sends a verification email to the email in the textbox. I need to know how to code the button so that it sends the verification email. Help would be appreciated.

    Nathaniel Washburn N-Soft Developer

    Sunday, January 13, 2013 6:52 PM

Answers

  • Ok, just sent myself an email from your email address...

    (also sent it to your email address)

    Make sure you change your password now, you have exposed it in the forum, and as easy as I used it, someone else can too.

    You will need to generate some NEW secure strings, since you will be changing your password.

    Here is working code as it stands.

    Feel free to send a test email to my account.

    By the way, I have had problems with yahoo and sending messages on port 465 before. I changed it to port 587 and set SSL to false. That solved the problem.

    Imports System.Net.Mail
    Imports System.Runtime.InteropServices
    Imports System.Security
    Public Class Form1
        Function SendEmail(ByVal Recipients As List(Of String), _
                              ByVal FromAddress As String, _
                              ByVal Subject As String, _
                              ByVal Body As String, _
                              ByVal UserName As String, _
                              ByVal Password As String, _
                              Optional ByVal Server As String = "smtp.mail.yahoo.com", _
                              Optional ByVal Port As Integer = 465, _
                              Optional ByVal Attachments As List(Of String) = Nothing) As String
            Dim Email As New MailMessage()
            Try
                Dim SMTPServer As New SmtpClient
                For Each Attachment As String In Attachments
                    Email.Attachments.Add(New Attachment(Attachment))
                Next
                Email.From = New MailAddress(FromAddress) 'DO NOT CHANGE ANYTHING IN THIS FUNCTION!!!
                For Each Recipient As String In Recipients
                    Email.To.Add(Recipient)
                Next
                Email.Subject = Subject
                Email.Body = Body
                SMTPServer.Host = Server
                SMTPServer.Port = Port
                SMTPServer.Credentials = New System.Net.NetworkCredential(UserName, Password) 'DO NOT CHANGE ANYTHING IN THIS FUNCTION!!!
                SMTPServer.EnableSsl = False
                SMTPServer.Send(Email)
                Email.Dispose()
                Return "Email to " & Recipients(0) & " from " & FromAddress & " was sent."
            Catch Ex As Exception
                Return Ex.ToString
            End Try
        End Function
        Public Function secureUserName() As SecureString
            Dim SecureString As New SecureString
            SecureString.AppendChar(Chr(79)) 'o
            SecureString.AppendChar(Chr(112)) 'p
            SecureString.AppendChar(Chr(101)) 'e
            SecureString.AppendChar(Chr(110)) 'n
            SecureString.AppendChar(Chr(83)) 's
            SecureString.AppendChar(Chr(116)) 't
            SecureString.AppendChar(Chr(117)) 'u
            SecureString.AppendChar(Chr(100)) 'd
            SecureString.AppendChar(Chr(121)) 'y
            SecureString.AppendChar(Chr(86)) 'v
            SecureString.AppendChar(Chr(101)) 'e
            SecureString.AppendChar(Chr(114)) 'r
            SecureString.AppendChar(Chr(105)) 'i
            SecureString.AppendChar(Chr(102)) 'f
            SecureString.AppendChar(Chr(105)) 'i
            SecureString.AppendChar(Chr(99)) 'c
            SecureString.AppendChar(Chr(97)) 'a
            SecureString.AppendChar(Chr(116)) 't
            SecureString.AppendChar(Chr(105)) 'i
            SecureString.AppendChar(Chr(111)) 'o
            SecureString.AppendChar(Chr(110)) 'n
            Return SecureString
        End Function
        Public Function securePassWord() As SecureString
            Dim SecureString As New SecureString
            SecureString.AppendChar(Chr(112))
            SecureString.AppendChar(Chr(111))
            SecureString.AppendChar(Chr(111))
            SecureString.AppendChar(Chr(112))
            SecureString.AppendChar(Chr(111))
            SecureString.AppendChar(Chr(111))
            SecureString.AppendChar(Chr(112))
            SecureString.AppendChar(Chr(111))
            SecureString.AppendChar(Chr(111))
            SecureString.AppendChar(Chr(49))
            Return SecureString
        End Function
    
        Public Shared Function ConvertToUnsecureString(ByVal securePassword As SecureString) As String
            If securePassword Is Nothing Then Throw New ArgumentNullException("securePassword")
            Dim unmanagedString As IntPtr = IntPtr.Zero
            Try
                unmanagedString = Marshal.SecureStringToGlobalAllocUnicode(securePassword)
                Return Marshal.PtrToStringUni(unmanagedString)
            Finally
                Marshal.ZeroFreeGlobalAllocUnicode(unmanagedString)
            End Try
        End Function
        '("OpenStudyVerification@yahoo.com", "poopoopoo1")
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            'Make all your changes HERE!!!!!!
            'Not in the sendemail function!!!!!!
            Dim Recipients As New List(Of String)
            Recipients.Add("liveloveinspiredie@gmail.com")
            Recipients.Add("OpenStudyVerification@yahoo.com")
            Dim FromEmailAddress As String = "OpenStudyVerification@yahoo.com" '<<<<<< CHANGE IT HERE!
            Dim Subject As String = "OpenStudy Verification Key"
            Dim Body As String = "test from Paul" 'My.Settings.AppVerified + "This is your OpenStudy verification key"
            Dim UserName As String = ConvertToUnsecureString(secureUserName) '<<<<<< CHANGE IT HERE!(not in send email function!), But don't change this!
            Dim Password As String = ConvertToUnsecureString(securePassWord) '<<<<<< CHANGE IT HERE!(not in send email function!), But don't change this!
            Dim Port As Integer = 587
            Dim Server As String = "smtp.mail.yahoo.com"
            Dim Attachments As New List(Of String)
            MsgBox(SendEmail(Recipients, FromEmailAddress, Subject, Body, UserName, Password, Server, Port, Attachments))
        End Sub
    End Class


    If you want something you've never had, you need to do something you've never done.

    Everyone should take the time to mark helpful posts and propose answers!

    Answer an interesting question?
    Create a wiki article about it!

    My Technet Wiki Articles



    • Edited by Paul Ishak Monday, January 14, 2013 1:57 AM
    • Proposed as answer by Paul Ishak Monday, January 14, 2013 3:03 AM
    • Marked as answer by Paul Ishak Monday, January 14, 2013 4:27 PM
    Monday, January 14, 2013 1:38 AM
  • I LOVE YOU. It works! :D

    Nathaniel Washburn N-Soft Developer

    Now please don't forget to:

    1.) Change your yahoo account password, as it is now publicly visible to the entire world.

    2.) Generate new securestrings

    3.) Mark helpful posts and answers ;)

    Please let me know if you have any further questions ;)


    If you want something you've never had, you need to do something you've never done.

    Everyone should take the time to mark helpful posts and propose answers!

    Answer an interesting question?
    Create a wiki article about it!

    My Technet Wiki Articles

    • Marked as answer by NSoft Studios Monday, January 14, 2013 2:32 PM
    Monday, January 14, 2013 2:01 AM

All replies

  • I posted an answer on how to send an email here:

    http://social.msdn.microsoft.com/Forums/en-US/vblanguage/thread/f040bf19-6474-421c-958b-7aa19973b328

    But I want to stress that if you have your "sending" account's information embedded into your exe, that information will be viewable with a hex editor, so you should bear this in mind when proceeding. Let me see if I can get you a different example...


    If you want something you've never had, you need to do something you've never done.

    Everyone should take the time to mark helpful posts and propose answers!

    Answer an interesting question?
    Create a wiki article about it!

    My Technet Wiki Articles

    Sunday, January 13, 2013 7:09 PM
  • So maybe the example I linked you to in combination with a securestring, I wasn't able to find anything with the hex editor... You should verify this yourself for your own peace of mind though.

    Imports System.Net.Mail
    Imports System.Runtime.InteropServices
    Imports System.Security
    Public Class Form1
        Function SendEmail(ByVal Recipients As List(Of String), _
                          ByVal FromAddress As String, _
                          ByVal Subject As String, _
                          ByVal Body As String, _
                          ByVal UserName As String, _
                          ByVal Password As String, _
                          Optional ByVal Server As String = "smtp.gmail.com", _
                          Optional ByVal Port As Integer = 587, _
                          Optional ByVal Attachments As List(Of String) = Nothing) As String
            Dim Email As New MailMessage()
            Try
                Dim SMTPServer As New SmtpClient
                For Each Attachment As String In Attachments
                    Email.Attachments.Add(New Attachment(Attachment))
                Next
                Email.From = New MailAddress(FromAddress)
                For Each Recipient As String In Recipients
                    Email.To.Add(Recipient)
                Next
                Email.Subject = Subject
                Email.Body = Body
                SMTPServer.Host = Server
                SMTPServer.Port = Port
                SMTPServer.Credentials = New System.Net.NetworkCredential(UserName, Password)
                SMTPServer.EnableSsl = True
                SMTPServer.Send(Email)
                Email.Dispose()
                Return "Email to " & Recipients(0) & " from " & FromAddress & " was sent."
            Catch Ex As Exception
                Return Ex.Message
            End Try
        End Function
    Public Function secureUserName() As SecureString
            Dim SecureString As New SecureString
            SecureString.AppendChar(Chr(117))
            SecureString.AppendChar(Chr(115))
            SecureString.AppendChar(Chr(101))
            SecureString.AppendChar(Chr(114))
            SecureString.AppendChar(Chr(110))
            SecureString.AppendChar(Chr(97))
            SecureString.AppendChar(Chr(109))
            SecureString.AppendChar(Chr(101))
            Return SecureString
        End Function
        Public Function securePassWord() As SecureString
            Dim SecureString As New SecureString
            SecureString.AppendChar(Chr(112))
            SecureString.AppendChar(Chr(97))
            SecureString.AppendChar(Chr(115))
            SecureString.AppendChar(Chr(115))
            SecureString.AppendChar(Chr(119))
            SecureString.AppendChar(Chr(111))
            SecureString.AppendChar(Chr(114))
            SecureString.AppendChar(Chr(100))
            Return SecureString
        End Function
        Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
            Dim Recipients As New List(Of String)
            Recipients.Add("recipient@gmail.com")
            Dim FromEmailAddress As String = Recipients(0)
            Dim Subject As String = "Test From VB."
            Dim Body As String = "email body text, if you are reading this from your gmail account, the program worked."
            Dim UserName As String = ConvertToUnsecureString(secureUserName)
            Dim Password As String = ConvertToUnsecureString(securePassword)
            Dim Port As Integer = 587
            Dim Server As String = "smtp.gmail.com"
            Dim Attachments As New List(Of String)
            MsgBox(SendEmail(Recipients, FromEmailAddress, Subject, Body, UserName, Password, Server, Port, Attachments))
        End Sub
        Public Shared Function ConvertToUnsecureString(ByVal securePassword As SecureString) As String
            If securePassword Is Nothing Then Throw New ArgumentNullException("securePassword")
            Dim unmanagedString As IntPtr = IntPtr.Zero
            Try
                unmanagedString = Marshal.SecureStringToGlobalAllocUnicode(securePassword)
                Return Marshal.PtrToStringUni(unmanagedString)
            Finally
                Marshal.ZeroFreeGlobalAllocUnicode(unmanagedString)
            End Try
        End Function
    End Class
    


    Please note, the secure strings I placed in there should be replaced with securestrings that reflect your username and password. I also created a utility for writing the declaration of your securestrings, but this should be used in an entirely different project, just for the purpose of writing some code for you.

        Function MakeSecureStringDeclaration(ByVal [String] As String, ByVal DeclarationName As String) As String
            Dim SB As New StringBuilder
            SB.Append("Public Function " & DeclarationName & "() As SecureString" & vbCrLf)
            SB.Append(Space(4) & "Dim SecureString As New SecureString" & vbCrLf)
            For Each C As Char In [String]
                SB.Append(Space(4) & "SecureString.AppendChar(Chr(" & Asc(C).ToString & "))" & vbCrLf)
            Next
            SB.Append(Space(4) & "Return SecureString" & vbCrLf)
            SB.Append("End Function")
            Clipboard.SetText(SB.ToString)
            Return SB.ToString
        End Function


    If you want something you've never had, you need to do something you've never done.

    Everyone should take the time to mark helpful posts and propose answers!

    Answer an interesting question?
    Create a wiki article about it!

    My Technet Wiki Articles


    • Edited by Paul Ishak Sunday, January 13, 2013 7:57 PM
    Sunday, January 13, 2013 7:51 PM
  • The server doesn't change depending on the email service the recipient is using, right? Like, if the recipient is using yahoomail then it doesn't change to smtp.mail.yahoo.net, right? It only depends on my email, doesn't it?

    EDIT: Also, where do I put my email so that it knows what the sending email is?



    Sunday, January 13, 2013 10:48 PM
  • The server doesn't change depending on the email service the recipient is using, right? Like, if the recipient is using yahoomail then it doesn't change to smtp.mail.yahoo.net, right? It only depends on my email, doesn't it?

    EDIT: Also, where do I put my email so that it knows what the sending email is?



    Correct, your sending settings are dependent on the account that is sending. 

    question 2:

    I told you to use the "utility function" I made in a whole different project. What this function will do is it will generate the delcaration for a secure string(so your embedded account details cannot be seen from a hex editor)

    When you have generated the secure strings(one for secureUserName, and one of securePassWord), find the function of those name in the example, and replace them with the generated code.

    So run this from a whole other project(this will write your secure string for you, and put it on the clipboard, then you can place the generated code in the email example)

    Imports System.Text
    Public Class Form1
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim TmpUserName As String = InputBox("Please Enter Your UserName")
            Dim TmpPassword As String = InputBox("Please Ender Your Password")
            If TmpUserName = "" Then Exit Sub
            If TmpPassword = "" Then Exit Sub
            Dim Result As String = MakeSecureStringDeclaration(TmpUserName, "secureUserName")
            Result = Result & vbCrLf & MakeSecureStringDeclaration(TmpPassword, "securePassWord")
            Clipboard.SetText(Result)
            MsgBox("The following generated code has been placed on the clipboard:" & vbCrLf & vbCrLf & Result)
        End Sub
        Function MakeSecureStringDeclaration(ByVal [String] As String, ByVal DeclarationName As String) As String
            Dim SB As New StringBuilder
            SB.Append("Public Function " & DeclarationName & "() As SecureString" & vbCrLf)
            SB.Append(Space(4) & "Dim SecureString As New SecureString" & vbCrLf)
            For Each C As Char In [String]
                SB.Append(Space(4) & "SecureString.AppendChar(Chr(" & Asc(C).ToString & "))" & vbCrLf)
            Next
            SB.Append(Space(4) & "Return SecureString" & vbCrLf)
            SB.Append("End Function")
            Return SB.ToString
        End Function
    End Class


    If you want something you've never had, you need to do something you've never done.

    Everyone should take the time to mark helpful posts and propose answers!

    Answer an interesting question?
    Create a wiki article about it!

    My Technet Wiki Articles



    • Edited by Paul Ishak Monday, January 14, 2013 12:36 AM
    Sunday, January 13, 2013 11:37 PM
  • Okay, so now where do I put the address that I will use to send the email?

    EDIT: Actually, I figured this out. But, I get failed to send email. Is it because of this?

    Recipients.Add(TextBox1.Text + "@" + TextBox2.Text)

    EDIT 2: I got it fixed. The error goes away. But, I don't get the email now.

    EDIT 3: No, I did not.


    Nathaniel Washburn N-Soft Developer




    Monday, January 14, 2013 12:29 AM
  • Okay, so now where do I put the address that I will use to send the email?

    Nathaniel Washburn N-Soft Developer

    Look in the example:

    Where it says recipients.Add("recipient@gmail.com")

    you can replace that with:

    recipients.add(textbox1.text), or however the user is inputting their email address.

    You can also add multiple recipients.

    Also replace this line:

    Dim FromEmailAddress As String = Recipients(0)

    with 

    Dim FromEmailAddress As String = "your sending email address here"

        Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
            Dim Recipients As New List(Of String)
            Recipients.Add("recipient@gmail.com")
            Dim FromEmailAddress As String = Recipients(0)
            Dim Subject As String = "Test From VB."
            Dim Body As String = "email body text, if you are reading this from your gmail account, the program worked."
            Dim UserName As String = ConvertToUnsecureString(secureUserName)
            Dim Password As String = ConvertToUnsecureString(securePassword)
            Dim Port As Integer = 587
            Dim Server As String = "smtp.gmail.com"
            Dim Attachments As New List(Of String)
            MsgBox(SendEmail(Recipients, FromEmailAddress, Subject, Body, UserName, Password, Server, Port, Attachments))
        End Sub

    • Edited by Paul Ishak Monday, January 14, 2013 12:55 AM
    Monday, January 14, 2013 12:31 AM
  • Okay, so now where do I put the address that I will use to send the email?

    EDIT: Actually, I figured this out. But, I get failed to send email. Is it because of this?

    Recipients.Add(TextBox1.Text + "@" + TextBox2.Text)


    Nathaniel Washburn N-Soft Developer


    If TextBox1.Text + "@" + Textbox2.text produces something like this:

    "recipient@gmail.com", that the is the correct format.

    We should back up for a minute here and let me ask you:

    Is your sender email address in the "Gmail" domain? If not, then we need to adjust the send email function's setting accordingly.

    Please tell what is the @domain.com part of your sending email address?


    • Edited by Paul Ishak Monday, January 14, 2013 12:55 AM
    Monday, January 14, 2013 12:47 AM
  • This is what I have in my code.

    Function SendEmail(ByVal Recipients As List(Of String), _
                          ByVal FromAddress As String, _
                          ByVal Subject As String, _
                          ByVal Body As String, _
                          ByVal UserName As String, _
                          ByVal Password As String, _
                          Optional ByVal Server As String = "smtp.mail.yahoo.com", _
                          Optional ByVal Port As Integer = 465, _
                          Optional ByVal Attachments As List(Of String) = Nothing) As String
            Dim Email As New MailMessage()
            Try
                Dim SMTPServer As New SmtpClient
                For Each Attachment As String In Attachments
                    Email.Attachments.Add(New Attachment(Attachment))
                Next
                Email.From = New MailAddress("OpenStudyVerification@yahoo.com")
                For Each Recipient As String In Recipients
                    Email.To.Add(TextBox1.Text)
                Next
                Email.Subject = Subject
                Email.Body = Body
                SMTPServer.Host = Server
                SMTPServer.Port = Port
                SMTPServer.Credentials = New System.Net.NetworkCredential("OpenStudyVerification@yahoo.com", "poopoopoo1")
                SMTPServer.EnableSsl = True
                SMTPServer.Send(Email)
                Email.Dispose()
                Return "Email to " & Recipients(0) & " from " & FromAddress & " was sent."
            Catch Ex As Exception
                Return Ex.Message
            End Try
        End Function
        Public Function secureUserName() As SecureString
            Dim SecureString As New SecureString
            SecureString.AppendChar(Chr(79))
            SecureString.AppendChar(Chr(112))
            SecureString.AppendChar(Chr(101))
            SecureString.AppendChar(Chr(110))
            SecureString.AppendChar(Chr(83))
            SecureString.AppendChar(Chr(116))
            SecureString.AppendChar(Chr(117))
            SecureString.AppendChar(Chr(100))
            SecureString.AppendChar(Chr(121))
            SecureString.AppendChar(Chr(86))
            SecureString.AppendChar(Chr(101))
            SecureString.AppendChar(Chr(114))
            SecureString.AppendChar(Chr(105))
            SecureString.AppendChar(Chr(102))
            SecureString.AppendChar(Chr(105))
            SecureString.AppendChar(Chr(99))
            SecureString.AppendChar(Chr(97))
            SecureString.AppendChar(Chr(116))
            SecureString.AppendChar(Chr(105))
            SecureString.AppendChar(Chr(111))
            SecureString.AppendChar(Chr(110))
            Return SecureString
        End Function
        Public Function securePassWord() As SecureString
            Dim SecureString As New SecureString
            SecureString.AppendChar(Chr(112))
            SecureString.AppendChar(Chr(111))
            SecureString.AppendChar(Chr(111))
            SecureString.AppendChar(Chr(112))
            SecureString.AppendChar(Chr(111))
            SecureString.AppendChar(Chr(111))
            SecureString.AppendChar(Chr(112))
            SecureString.AppendChar(Chr(111))
            SecureString.AppendChar(Chr(111))
            SecureString.AppendChar(Chr(49))
            Return SecureString
        End Function
    
        Public Shared Function ConvertToUnsecureString(ByVal securePassword As SecureString) As String
            If securePassword Is Nothing Then Throw New ArgumentNullException("securePassword")
            Dim unmanagedString As IntPtr = IntPtr.Zero
            Try
                unmanagedString = Marshal.SecureStringToGlobalAllocUnicode(securePassword)
                Return Marshal.PtrToStringUni(unmanagedString)
            Finally
                Marshal.ZeroFreeGlobalAllocUnicode(unmanagedString)
            End Try
        End Function
    
        Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
            Dim Recipients As New List(Of String)
            Recipients.Add(TextBox1.Text)
            Dim FromEmailAddress As String = Recipients(0)
            Dim Subject As String = "OpenStudy Verification Key"
            Dim Body As String = My.Settings.AppVerified + "This is your OpenStudy verification key"
            Dim UserName As String = ConvertToUnsecureString(secureUserName)
            Dim Password As String = ConvertToUnsecureString(securePassWord)
            Dim Port As Integer = 465
            Dim Server As String = "smtp.mail.yahoo.com"
            Dim Attachments As New List(Of String)
            MsgBox(SendEmail(Recipients, FromEmailAddress, Subject, Body, UserName, Password, Server, Port, Attachments))
        End Sub


    Nathaniel Washburn N-Soft Developer

    Monday, January 14, 2013 1:02 AM
  • Ok, so it does look like you understood the utility, good. 

    This means that your problem has to do with your smtp settings.

    P.S. If that is your actual password, I suggest you remove it now.


    If you want something you've never had, you need to do something you've never done.

    Everyone should take the time to mark helpful posts and propose answers!

    Answer an interesting question?
    Create a wiki article about it!

    My Technet Wiki Articles

    Monday, January 14, 2013 1:05 AM
  • Change this line:

     Dim FromEmailAddress As String = Recipients(0)

    to

    Dim FromEmailAddress As String = "OpenStudyVerification@yahoo.com"

    And change this one:

     Email.From = New MailAddress("OpenStudyVerification@yahoo.com")

    Back to

        Email.From = New MailAddress(FromAddress)


    If you want something you've never had, you need to do something you've never done.

    Everyone should take the time to mark helpful posts and propose answers!

    Answer an interesting question?
    Create a wiki article about it!

    My Technet Wiki Articles

    Monday, January 14, 2013 1:10 AM
  • Unlike google, with yahoo, the username is the entire email address, so when you generate your securestrings, make sure that you enter:

    OpenStudyVerification@yahoo.com

    Instead of just

    OpenStudyVerification

    Let me know if all this works, I apologize about how complicated it seems, I promise it gets easier.


    If you want something you've never had, you need to do something you've never done.

    Everyone should take the time to mark helpful posts and propose answers!

    Answer an interesting question?
    Create a wiki article about it!

    My Technet Wiki Articles

    Monday, January 14, 2013 1:15 AM
  • Ok, just sent myself an email from your email address...

    (also sent it to your email address)

    Make sure you change your password now, you have exposed it in the forum, and as easy as I used it, someone else can too.

    You will need to generate some NEW secure strings, since you will be changing your password.

    Here is working code as it stands.

    Feel free to send a test email to my account.

    By the way, I have had problems with yahoo and sending messages on port 465 before. I changed it to port 587 and set SSL to false. That solved the problem.

    Imports System.Net.Mail
    Imports System.Runtime.InteropServices
    Imports System.Security
    Public Class Form1
        Function SendEmail(ByVal Recipients As List(Of String), _
                              ByVal FromAddress As String, _
                              ByVal Subject As String, _
                              ByVal Body As String, _
                              ByVal UserName As String, _
                              ByVal Password As String, _
                              Optional ByVal Server As String = "smtp.mail.yahoo.com", _
                              Optional ByVal Port As Integer = 465, _
                              Optional ByVal Attachments As List(Of String) = Nothing) As String
            Dim Email As New MailMessage()
            Try
                Dim SMTPServer As New SmtpClient
                For Each Attachment As String In Attachments
                    Email.Attachments.Add(New Attachment(Attachment))
                Next
                Email.From = New MailAddress(FromAddress) 'DO NOT CHANGE ANYTHING IN THIS FUNCTION!!!
                For Each Recipient As String In Recipients
                    Email.To.Add(Recipient)
                Next
                Email.Subject = Subject
                Email.Body = Body
                SMTPServer.Host = Server
                SMTPServer.Port = Port
                SMTPServer.Credentials = New System.Net.NetworkCredential(UserName, Password) 'DO NOT CHANGE ANYTHING IN THIS FUNCTION!!!
                SMTPServer.EnableSsl = False
                SMTPServer.Send(Email)
                Email.Dispose()
                Return "Email to " & Recipients(0) & " from " & FromAddress & " was sent."
            Catch Ex As Exception
                Return Ex.ToString
            End Try
        End Function
        Public Function secureUserName() As SecureString
            Dim SecureString As New SecureString
            SecureString.AppendChar(Chr(79)) 'o
            SecureString.AppendChar(Chr(112)) 'p
            SecureString.AppendChar(Chr(101)) 'e
            SecureString.AppendChar(Chr(110)) 'n
            SecureString.AppendChar(Chr(83)) 's
            SecureString.AppendChar(Chr(116)) 't
            SecureString.AppendChar(Chr(117)) 'u
            SecureString.AppendChar(Chr(100)) 'd
            SecureString.AppendChar(Chr(121)) 'y
            SecureString.AppendChar(Chr(86)) 'v
            SecureString.AppendChar(Chr(101)) 'e
            SecureString.AppendChar(Chr(114)) 'r
            SecureString.AppendChar(Chr(105)) 'i
            SecureString.AppendChar(Chr(102)) 'f
            SecureString.AppendChar(Chr(105)) 'i
            SecureString.AppendChar(Chr(99)) 'c
            SecureString.AppendChar(Chr(97)) 'a
            SecureString.AppendChar(Chr(116)) 't
            SecureString.AppendChar(Chr(105)) 'i
            SecureString.AppendChar(Chr(111)) 'o
            SecureString.AppendChar(Chr(110)) 'n
            Return SecureString
        End Function
        Public Function securePassWord() As SecureString
            Dim SecureString As New SecureString
            SecureString.AppendChar(Chr(112))
            SecureString.AppendChar(Chr(111))
            SecureString.AppendChar(Chr(111))
            SecureString.AppendChar(Chr(112))
            SecureString.AppendChar(Chr(111))
            SecureString.AppendChar(Chr(111))
            SecureString.AppendChar(Chr(112))
            SecureString.AppendChar(Chr(111))
            SecureString.AppendChar(Chr(111))
            SecureString.AppendChar(Chr(49))
            Return SecureString
        End Function
    
        Public Shared Function ConvertToUnsecureString(ByVal securePassword As SecureString) As String
            If securePassword Is Nothing Then Throw New ArgumentNullException("securePassword")
            Dim unmanagedString As IntPtr = IntPtr.Zero
            Try
                unmanagedString = Marshal.SecureStringToGlobalAllocUnicode(securePassword)
                Return Marshal.PtrToStringUni(unmanagedString)
            Finally
                Marshal.ZeroFreeGlobalAllocUnicode(unmanagedString)
            End Try
        End Function
        '("OpenStudyVerification@yahoo.com", "poopoopoo1")
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            'Make all your changes HERE!!!!!!
            'Not in the sendemail function!!!!!!
            Dim Recipients As New List(Of String)
            Recipients.Add("liveloveinspiredie@gmail.com")
            Recipients.Add("OpenStudyVerification@yahoo.com")
            Dim FromEmailAddress As String = "OpenStudyVerification@yahoo.com" '<<<<<< CHANGE IT HERE!
            Dim Subject As String = "OpenStudy Verification Key"
            Dim Body As String = "test from Paul" 'My.Settings.AppVerified + "This is your OpenStudy verification key"
            Dim UserName As String = ConvertToUnsecureString(secureUserName) '<<<<<< CHANGE IT HERE!(not in send email function!), But don't change this!
            Dim Password As String = ConvertToUnsecureString(securePassWord) '<<<<<< CHANGE IT HERE!(not in send email function!), But don't change this!
            Dim Port As Integer = 587
            Dim Server As String = "smtp.mail.yahoo.com"
            Dim Attachments As New List(Of String)
            MsgBox(SendEmail(Recipients, FromEmailAddress, Subject, Body, UserName, Password, Server, Port, Attachments))
        End Sub
    End Class


    If you want something you've never had, you need to do something you've never done.

    Everyone should take the time to mark helpful posts and propose answers!

    Answer an interesting question?
    Create a wiki article about it!

    My Technet Wiki Articles



    • Edited by Paul Ishak Monday, January 14, 2013 1:57 AM
    • Proposed as answer by Paul Ishak Monday, January 14, 2013 3:03 AM
    • Marked as answer by Paul Ishak Monday, January 14, 2013 4:27 PM
    Monday, January 14, 2013 1:38 AM
  • I LOVE YOU. It works! :D

    Nathaniel Washburn N-Soft Developer

    Monday, January 14, 2013 1:59 AM
  • I LOVE YOU. It works! :D

    Nathaniel Washburn N-Soft Developer

    Now please don't forget to:

    1.) Change your yahoo account password, as it is now publicly visible to the entire world.

    2.) Generate new securestrings

    3.) Mark helpful posts and answers ;)

    Please let me know if you have any further questions ;)


    If you want something you've never had, you need to do something you've never done.

    Everyone should take the time to mark helpful posts and propose answers!

    Answer an interesting question?
    Create a wiki article about it!

    My Technet Wiki Articles

    • Marked as answer by NSoft Studios Monday, January 14, 2013 2:32 PM
    Monday, January 14, 2013 2:01 AM