I have the following code attached to a submit button on a form. The record inserts into the database fine, but when I want to send an email confirmation it comes back with the error:
"The server rejected one or more recipient addresses. The server response was: 550 mail from 81.155.200.74 rejected: administrative prohibition"
If I just have the email code, then the form submits the email fine.
Where is my code wrong?
"The server rejected one or more recipient addresses. The server response was: 550 mail from 81.155.200.74 rejected: administrative prohibition"
If I just have the email code, then the form submits the email fine.
Where is my code wrong?
Code:
Sub btnSubmit_Click(s As Object, e As EventArgs)
Dim conRubicCallBack As SqlConnection
Dim strInsert As String
Dim cmdInsert As SqlCommand
conRubicCallBack = New SqlConnection("Server=ANDREW-LAPTOP\SQLEXPRESS;UID=sa;PWD=administrator;database=Rubic" )
strInsert = "Insert dbo.Callbacks (Title, Forename, Surname, EmailAddress, TelephoneNumber, DaytoCall, TimetoCall, OptOut) Values (@Title, @Forename, @Surname, @EmailAddress, @TelephoneNumber, @DaytoCall, @TimetoCall, @OptOut)"
cmdInsert = New SqlCommand(strInsert, conRubicCallBack)
cmdInsert.Parameters.Add( "@Title", Title.SelectedItem.Text)
cmdInsert.Parameters.Add( "@Forename", Forename.Text)
cmdInsert.Parameters.Add( "@Surname", Surname.Text)
cmdInsert.Parameters.Add( "@EmailAddress", Email_Address.Text)
cmdInsert.Parameters.Add( "@TelephoneNumber", Telephone.Text)
cmdInsert.Parameters.Add( "@DaytoCall", SqlDbType.DateTime).Value = Call_Day.Text
cmdInsert.Parameters.Add( "@TimetoCall", Call_Time.SelectedItem.Text)
cmdInsert.Parameters.Add( "@OptOut", SqlDbType.bit).Value = OptOut.Checked
conRubicCallBack.Open()
cmdInsert.ExecuteNonQuery()
conRubicCallBack.Close()
'Create instance of new mail message
Dim objMail As New MailMessage()
'Create the To & From Addresses
objMail.From = Email_Address.Text
objMail.To = "andrew@primagic.co.uk"
'Set the subject
objMail.Subject = "Please call me back"
'Email format - Can be text or html
objMail.BodyFormat = MailFormat.Html
'Set the body of the email
objMail.Body = "<html><head><title>Please call me back</title></head><body>"+"<p>Title: "+Title.SelectedItem.Text+"</p>"+"<p>Name: "+Forename.Text+"</p>"+"<p>Surname: "+ Surname.Text+"</p>"+"<p>Email: "+Email_Address.Text+"</p>"+"<p>Telephone: "+Telephone.Text+"</p>"+"<p>Date: "+Call_Day.Text+"</p>"+"<p>Time: "+Call_Time.SelectedItem.Text+"</p>"+"</body></html>"
'smtp server
SmtpMail.SmtpServer = "mrvnet.kundenserver.de"
'Send the message
SmtpMail.Send(objMail)
panelSendEmail.Visible = false
panelMailSent.Visible = true
End Sub