We are trying to use the following code to allow users to complete a form and send email to a specific department.
The sender's email address is used to send acknowledgement of the receipt of his / her email.
The code below uses smtp replay to send out an receive emails through Outlook Exchange Server.
Error: Client does not have permission to submit mail to this server. The server response was 4.7.1.Relay access denied
Here is the code:
Imports System.Net
Imports System.Net.Mail
Imports System.Net.Configuration
Partial Class VB
Inherits System.Web.UI.Page
Protected Sub Send(ByVal sender As Object, ByVal e As EventArgs)
Dim smtpSection As SmtpSection = CType(ConfigurationManager.GetSection("system.net/mailSettings/smtp"), SmtpSection)
Dim mm As MailMessage = New MailMessage(smtpSection.From, "noReply@domain.com")
mm.Subject = txtSubject.Text.Trim
mm.Body = "Name: " & txtName.Text & "<br /><br />Email: " & txtEmail.Text & "<br />" & txtBody.Text
mm.IsBodyHtml = True
Dim smtp As SmtpClient = New SmtpClient
smtp.Host = relay@domain.com
smtp.EnableSsl = false
smtp.UseDefaultCredentials = false
smtp.Port = 25
smtp.Send(mm)
lblMessage.Text = "Email sent sucessfully."
End Sub
End Class