473,569 Members | 2,984 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.co m"
smtpClient.Port = "25"
smtpClient.UseD efaultCredentia ls = False
smtpClient.Cred entials = New
Net.NetworkCred ential("us**@do main.com", "password")
smtpClient.Deli veryMethod =
System.Net.Mail .SmtpDeliveryMe thod.Network

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

System.Net.Mail .SmtpFailedReci pientException: Mailbox unavailable. The
server response was: No such user here at
System.Net.Mail .SmtpTransport. SendMail(MailAd dress sender,
MailAddressColl ection recipients, String deliveryNotify,
SmtpFailedRecip ientException& exception) at
System.Net.Mail .SmtpClient.Sen d(MailMessage message) at
MyNamespace.Web .UI.Form.Contac t.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
defaultCredenti als = "true"
host = "mail.domain.co m"
password = "password"
port = "25"

userName = "us**@domain.co m" />
</smtp>
</mailSettings>
</system.net>

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

Private Sub bSubmit_Click(B yVal sender As Object, ByVal e As
System.EventArg s) 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(tb Email.Text,
tbName.Text)
Else
.From = New System.Net.Mail .MailAddress(tb Email.Text)
End If

' Define subject
If Me.SubjectVisib le 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

Nov 15 '06 #1
1 5030
See:

http://sholliday.spaces.live.com/blog/
2/8/2006
Smarter Email/Smtp setup with DotNet Configuration Sections (1.1 and 2.0)
"shapper" <md*****@gmail. comwrote in message
news:11******** **************@ k70g2000cwa.goo glegroups.com.. .
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.co m"
smtpClient.Port = "25"
smtpClient.UseD efaultCredentia ls = False
smtpClient.Cred entials = New
Net.NetworkCred ential("us**@do main.com", "password")
smtpClient.Deli veryMethod =
System.Net.Mail .SmtpDeliveryMe thod.Network

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

System.Net.Mail .SmtpFailedReci pientException: Mailbox unavailable. The
server response was: No such user here at
System.Net.Mail .SmtpTransport. SendMail(MailAd dress sender,
MailAddressColl ection recipients, String deliveryNotify,
SmtpFailedRecip ientException& exception) at
System.Net.Mail .SmtpClient.Sen d(MailMessage message) at
MyNamespace.Web .UI.Form.Contac t.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
defaultCredenti als = "true"
host = "mail.domain.co m"
password = "password"
port = "25"

userName = "us**@domain.co m" />
</smtp>
</mailSettings>
</system.net>

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

Private Sub bSubmit_Click(B yVal sender As Object, ByVal e As
System.EventArg s) 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(tb Email.Text,
tbName.Text)
Else
.From = New System.Net.Mail .MailAddress(tb Email.Text)
End If

' Define subject
If Me.SubjectVisib le 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

Nov 15 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
7031
by: Paul Lamonby | last post by:
Hi, I am sending a file from the server as an email attachment. The file is being attached no problem and sending the email, but I get an error when I try to open it saying it is corrupt. Obviuosly, the file is fine on the server, so the attachment code I am using must be corrupting it, but I dont know what it is: // send email with...
0
522
by: praba kar | last post by:
Dear All, I have doubt regarding mail sending smtplib module. The below code is I used to send a mail. ########################################## import email.Message import email.Utils import mimetypes import os,string
3
6811
by: VB Programmer | last post by:
I have an ASPX page where I send out emails through my mail server mail.MyDomain.com. When I send emails to MyName@MyDomain.com it sends PERFECTLY. When I try sending an email to any other address (non-MyDomain.com address) I get the following error: The server rejected one or more recipient addresses. The server response was: 550 You must...
3
3601
by: Ant | last post by:
Hi, I'm using the MailMessage & smtpMail classes in System.Web.Mail to send mail, however it's not sending any emails. I'm using it on a Windows 2003 server. The simplest way to use this is smtpMail.Send("from@here.com", to@there.com, "Message subject", "Message Body") I'm sending it to my own email address on a different server using...
1
8161
by: Eric Sheu | last post by:
Greetings, I have been searching the web like mad for a solution to my SMTP problem. I am using Windows Server 2003 and ASP.NET 2.0 w/ C# to send out e-mails from a web site I have created to the members of my organization. I think my problem is incorrectly setting the settings on my server or an authentication problem. Here is the code I...
2
12150
by: =?Utf-8?B?QWRl?= | last post by:
HI All, I am encountering the following error when I try to send an email through a SMTP server. I believe the problem lies with the authentication part when the network crednetials are used, error is thrown at the .send point. Error is: The following error occured Sending an email: System.ApplicationException: An error occurred sending...
9
3443
by: JoeP | last post by:
Hi All, How can I find the reason for such an error: Failure sending mail. Some Code... oMailMessage.IsBodyHtml = False oMailMessage.Body = cEmailBody Dim oSMTP As New SmtpClient oSMTP.Send(oMailMessage) (in this line I am getting the above err)
7
3322
by: bleachie | last post by:
Hey, I just need some help, my form seems to not send me all of the 'guestNames' and 'guestEmails' forms. i use this function to add more guestnames and guestemail fields based on the number of guests added. form.php function createGuestNameAndEmailElements() {
10
5058
by: Markgoldin | last post by:
I am sending an XML data from not dontnet process to a .Net via socket listener. Here is a data sample: <VFPData> <serverdata> <coderun>updateFloor</coderun> <area>MD2</area> <zone>BOXING</zone> <status>Running</status> <job>1000139233</job>
31
12628
by: happyse27 | last post by:
Hi All, I am trying for weeks how to send email from windows pc, which from my gmail account to my hotmail account. Using net::smtp module sending email failed,Kindly assist. (for the item d it is working for normal email servers, but NOT with gmail server, I am very puzzled still!!) Codes(item c below) It keeps complaining and logs and...
0
7703
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7619
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7930
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8138
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7681
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7983
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6290
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3662
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.