Click here to Skip to main content
15,887,477 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have made a form and I want to send emails with it, I have name subject email and password but it wont send... could anyone help tell me why? all I get is 'Failed to send message'
*(in the code I have removed the emails and changed them to example it was not like that when I was testing*
sorry this is a long message DX

VB
Dim OMail As New MailMessage()
        Dim oServer As New SmtpClient
        Dim name As String
        Dim theCredential As System.Net.NetworkCredential = New System.Net.NetworkCredential(Email.Text, Password.Text)
        oServer.Credentials = theCredential
        name = FName.Text + Lname.Text

        ' Set recipient email address, please change it to yours
        OMail.From = New MailAddress(Email.Text)

        ' Set recipient email address, please change it to yours
        OMail.To.Add("Example@outlook.com")

        ' Set email subject
        OMail.Subject = Subject.Text

        ' Set email body
        OMail.Body = Template.Text + Message.Text + "This message was sent by " + name + " @ " + Email.Text

        ' Your Office 365 SMTP server address, 
        ' You should get it from outlook web access.
        oServer.Host = "smpt.live.com"

        ' user authentication should use your 
        'Email address as the user name. 
        oServer.Credentials = New Net.NetworkCredential(My.Settings.Email, My.Settings.Emailpass)

        ' Set 587 port
        oServer.Port = 587

        Try
            strMsg = "start to send Feedback..." & vbCrLf & "Please wait"
            strTitle = "Sending Email"
            Ret_type = MsgBox(strMsg, vbOKOnly + vbInformation, strTitle)
            '
            oServer.Send(OMail)
            '
            strMsg = "email was sent successfully!" & vbCrLf & "If a reply is needed you sould get one in the next few days!"
            strTitle = "Email sent"
            Ret_type = MsgBox(strMsg, vbOKOnly + vbInformation, strTitle)

        Catch ex As Exception

            strMsg = "failed to send email with the following error:" & vbCrLf & vbCrLf & "'" & ex.Message & "'"
            strTitle = "Critical Error Encountered"
            Ret_type = MsgBox(strMsg, vbOKOnly + vbCritical, strTitle)
        End Try


What I have tried:

I have tried other peoples code, but none got as far as this one did so I think this is my best bet.
Posted
Updated 19-Mar-16 14:35pm
Comments
Garth J Lancaster 19-Mar-16 21:06pm    
>> oServer.Host = "smpt.live.com"

thats an obvious mistake right ? ie, you changed it for posting here ??

1 solution

You should learn to use the debugger as soon as possible. Rather than guessing what your code is doing, It is time to see your code executing and ensuring that it does what you expect.

The debugger allow you to follow the execution line by line, inspect variables and you will see that there is a point where it stop doing what you expect.
Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]
http://docs.oracle.com/javase/7/docs/technotes/tools/windows/jdb.html[^]
https://www.jetbrains.com/idea/help/debugging-your-first-java-application.html[^]

Use the debugger to see WHERE is the error and to see what is the exact error message.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900