0

So I have an asp.net server running on discountasp.net and for whatever reason when I just published the new version of the website it stopped sending emails. I tried changing the code back to exactly how it was done in the old website and it didn't work. I've tried many other solutions to no avail. Here's the old code:

 Dim message As New MailMessage
        message.IsBodyHtml = True
        message.From = New MailAddress("example@mydomain.com", "inquiry@mydomain.com")
        If Me.ddlSendTo.SelectedValue = 1 Then
            message.To.Add(New MailAddress("sales@mydomain.com"))
            message.Subject = "Sales Inquiry From mydomain.com"
        ElseIf Me.ddlSendTo.SelectedValue = 2 Then
            message.To.Add(New MailAddress("support@mydomain.com"))
            message.Subject = "Support Question From mydomain.com"
        End If

        Dim sb As New StringBuilder()
        sb.Append("The following message was sent from a user of our website as a request for more information.<br/><br/>")
        sb.Append("Here is the message they sent:<br/><br/>")
        sb.Append("Sender's Name: " & Me.txtSenderName.Text & "<br/>")
        sb.Append("Senders Email: <a href='mailto:" & Me.txtSenderEmail.Text & "'>" & Me.txtSenderEmail.Text & "</a><br/>")
        sb.Append("Company Name: " & Me.txtCompany.Text & "<br/>")
        sb.Append("Phone Number: " & Me.txtPhone.Text & "<br/><br/>")
        sb.Append("Subject: " & Me.txtSubject.Text & "<br/>")
        sb.Append("Message: " & Me.txtEmailMsg.Text)
        message.Body = sb.ToString()

        Try
            Dim client As New SmtpClient()
            client.Host = "localhost"
            client.Send(message)
        Catch ex As SmtpException
            Me.errors.InnerHtml = ex.Message & " local host message"
            Return
        End Try

Here's my current iteration that is still not working:

Dim toEmail As String
    Dim subject As String
    If Me.ddlSendTo.SelectedValue = 1 Then
        If isTesting() Then
            toEmail = GetTesterEmail()
        Else
            toEmail = "sales@mydomain.com"
        End If

        subject = "Sales Inquiry From MyDomain.com"
    ElseIf Me.ddlSendTo.SelectedValue = 2 Then
        If isTesting() Then
            toEmail = GetTesterEmail()
        Else
            toEmail = "support@mydomain.com"
        End If
        subject = "Support Question From MyDomain.com"
    End If

    Dim sb As New StringBuilder()
    sb.Append("The following message was sent from a user of our website as a request for more information.<br/><br/>")
    sb.Append("Here Is the message they sent:<br/><br/>")
    sb.Append("Sender's Name: " & Me.txtName.Value & "<br/>")
    sb.Append("Senders Email: <a href='mailto:" & Me.txtEmail.Value & "'>" & Me.txtEmail.Value & "</a><br/>")
    sb.Append("Company Name: " & Me.txtCompany.Value & "<br/>")
    sb.Append("Phone Number: " & Me.txtPhone.Value & "<br/><br/>")
    sb.Append("Subject: " & Me.txtSubject.Value & "<br/>")
    sb.Append("Message: " & Me.txtMessage.Value)
    'message.Body = sb.ToString()
    Dim message As New MailMessage("postmaster@mydomain.com", toEmail, subject, sb.ToString())
    message.IsBodyHtml = True
    Try
        Dim client As New SmtpClient()
        client.Host = "smtp.mydomain.com"
        client.Port = 25
        client.Credentials = New System.Net.NetworkCredential("postmaster@mydomain.com", "password")
        client.Send(message)
    Catch ex As SmtpException
        Me.errors.Text = ex.Message & " local host message"
        Return
    End Try

I tried leaving off network credentials, leaving off port, leaving off the @mydomain.com on the network credentials. Nothing works

Jake
  • 113
  • 7
  • Could you show us the exception? – Win Jun 29 '17 at 19:17
  • well i was trying to but I've just now realized that when I replace vb files on my site it's not reflecting the changes. All I currently have it printing out is "Failure Sending Mail" which is the exception message. So anyway now i gotta figure out why my vb files aren't getting updated before I do anything else – Jake Jun 29 '17 at 19:49
  • The SMTP server requires a secure connection or the client was not authenticated. The server response was: Authentication required at System.Net.Mail.RecipientCommand.CheckResponse(SmtpStatusCode statusCode, String response) at System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String deliveryNotify, Boolean allowUnicode, SmtpFailedRecipientException& exception) at System.Net.Mail.SmtpClient.Send(MailMessage message) at Skrollr_Test.Contact.btnSubmit_Click(Object sender, ImageClickEventArgs e) – Jake Jun 30 '17 at 14:18
  • @Win I had to cut off the very end where it says what line it was on but it's just the line where I do Client.send. Anyway I got the codebehind file to finally update but I can't get it to do so reliably. That's a whole other problem though. – Jake Jun 30 '17 at 14:19

0 Answers0