Sending email with ASP.NET 2.0




I created an ASP.NET 2.0 custom control which includes various
TextBoxes, Labels and a button.
Basically is a contact form. When the button is pressed the values are
sent by email.

I want to use the mailSettings values in my Web.Config file.

Everything works fine if I use in my bSubmit function:

smtpClient.Host = ""
smtpClient.Port = "25"
smtpClient.UseDefaultCredentials = False
smtpClient.Credentials = New
Net.NetworkCredential("(e-mail address removed)", "password")
smtpClient.DeliveryMethod =

But if I don't include this code I get the error:

System.Net.Mail.SmtpFailedRecipientException: Mailbox unavailable. The
server response was: No such user here at
System.Net.Mail.SmtpTransport.SendMail(MailAddress sender,
MailAddressCollection recipients, String deliveryNotify,
SmtpFailedRecipientException& exception) at
System.Net.Mail.SmtpClient.Send(MailMessage message) at
MyNamespace.Web.UI.Form.Contact.bSubmit_Click(Object sender, EventArgs

Shouldn't it be using the Web.Config values?
And if yes, why am I getting an error if the values are the same:

<smtp deliveryMethod = "network">
defaultCredentials = "true"
host = ""
password = "password"
port = "25"

userName = "(e-mail address removed)" />

My bSubmit_Click function, inside my custom control, is the following:

Private Sub bSubmit_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles bSubmit.Click

' Create new mail message
Dim message As New System.Net.Mail.MailMessage

' Define mail message properties
With message

' Define various properties
.To.Add(New System.Net.Mail.MailAddress(Me.ToAddress,
.Body = tbMessage.Text
.IsBodyHtml = True

' Define fromMailAddress
If Me.NameVisible Then
.From = New System.Net.Mail.MailAddress(tbEmail.Text,
.From = New System.Net.Mail.MailAddress(tbEmail.Text)
End If

' Define subject
If Me.SubjectVisible Then
.Subject = tbSubject.Text
End If

End With

' Define a new mail SMTP client
Dim smtpClient As New System.Net.Mail.SmtpClient

' Send the mail message and define sent property

' Send the mail message

' Define sent property
Me.Sent = True

Catch ex As Exception

' Define sent property
Me.Sent = False

End Try

' Raise the OnFormSubmited event
RaiseEvent FormSubmited(Me, EventArgs.Empty)

End Sub



Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question