S
shapper
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("(e-mail address removed)", "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:
<system.net>
<mailSettings>
<smtp deliveryMethod = "network">
<network
defaultCredentials = "true"
host = "mail.domain.com"
password = "password"
port = "25"
userName = "(e-mail address removed)" />
</smtp>
</mailSettings>
</system.net>
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 client
Dim smtpClient As New System.Net.Mail.SmtpClient
' Send the mail message and define sent property
Try
' Send the mail message
smtpClient.Send(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
Thanks,
Miguel
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("(e-mail address removed)", "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:
<system.net>
<mailSettings>
<smtp deliveryMethod = "network">
<network
defaultCredentials = "true"
host = "mail.domain.com"
password = "password"
port = "25"
userName = "(e-mail address removed)" />
</smtp>
</mailSettings>
</system.net>
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 client
Dim smtpClient As New System.Net.Mail.SmtpClient
' Send the mail message and define sent property
Try
' Send the mail message
smtpClient.Send(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
Thanks,
Miguel