Sending email with ASP.NET 2.0
-
Hello, 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 = "mail.domain.com" smtpClient.Port = "25" smtpClient.UseDefaultCredentials = False smtpClient.Credentials = New Net.NetworkCredential("user@domain.com", "password") smtpClient.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network 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 e) Shouldn't it be using the Web.Config values? And if yes, why am I getting an error if the values are the same: 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, Me.ToName)) .Body = tbMessage.Text .IsBodyHtml = True ' Define fromMailAddress If Me.NameVisible Then .From = New System.Net.Mail.MailAddress(tbEmail.Text, tbName.Text) Else .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