1

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:&nbsp;<asp:TextBox ID="txtFromAdress" runat="server" Columns="35"></asp:TextBox></p>
                <p>Subject:&nbsp;<asp:TextBox ID="txtSubject" runat="server" Columns="50"></asp:TextBox></p>
                <p>Message:&nbsp;<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
Bradley Uffner
  • 16,641
  • 3
  • 39
  • 76

1 Answers1

1

Open a command prompt and run the following command:

telnet smtp.office365.com 587

What is the response? If it produces the desired result then download a tool like Wireshark so that you can analyse the request and response.

w0051977
  • 15,099
  • 32
  • 152
  • 329
  • 'telnet' is not recognized as an internal or external command, operable program or batch file. – badapaqadadap Jun 06 '17 at 20:47
  • Make sure Telnet is installed by following these instructions: https://kb.ctera.com/article/how-to-open-a-telnet-session-on-windows-7-or-windows-8-os-16.html. Once installed let me know the outcome. – w0051977 Jun 06 '17 at 20:53
  • I talked to my it dept. they said it should work as is and suggested I try and do it in c# instead. so I am abandoning this attempt. Thank you for your help. – badapaqadadap Jun 13 '17 at 19:06