I am using visual studio 2017
- double checked the credentials
 - tried using print.debug from here
 tried printing to another file like this said to do Don't know how else to figure out why the code isn't working.
<%@ Page Language="VB" aspcompat=true Debug="true" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div><p>From: <asp:TextBox ID="txtFromAdress" runat="server" Columns="35"></asp:TextBox></p> <p>Subject: <asp:TextBox ID="txtSubject" runat="server" Columns="50"></asp:TextBox></p> <p>Message: <asp:TextBox ID="txtBody" runat="server" Columns="76" TextMode="multiLine" Rows="6"></asp:TextBox></p> <p><asp:Button ID="btnSend" runat="server" Text="Send Mail" /></p> </div> </form> Debug.print txtFromAdress Debug.print txtSubject Debug.print txtBody </body> </html>
Here is the code behind:
<%@ Page Language="VB" aspcompat=true Debug="true" %>
Imports System.Net.Mail
Public Class WebForm1
    Inherits System.Web.UI.Page
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    End Sub
    Protected Sub btnSend_Click(sender As Object, e As EventArgs) Handles btnSend.Click
        Dim mail As New MailMessage()
        mail.From = New MailAddress(txtFromAdress.Text.Trim)
        mail.To.Add("email@domain.com")
        mail.Subject = txtSubject.Text.Trim()
        mail.Body = txtBody.Text.Trim()
        Debug.print mail
        Dim SmtpClient As New SmtpClient("smtp.office365.com")
        SmtpClient.UseDefaultCredentials = False
        SmtpClient.EnableSsl = True
        SmtpClient.Port = 587
        SmtpClient.Credentials = New Net.NetworkCredential("email@domain.com", "pword")
        n = FreeFile()
Open "root/test.txt" For Output As #n
Print #n, mail
        Try
            SmtpClient.Send(mail)
        Catch ex As Exception
            MsgBox(Err.Number & vbNewLine & ex.Message)
        End Try