473,508 Members | 2,369 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Send email in Asp.Net 2.0

Hello,

I am trying to send an email using Asp.Net 2.0.

I am getting the following 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)

The strange thing is that the email box really exists.

My code is as follows:

1 ' Define user profile
2 Dim userProfile As ProfileCommon =
Profile.GetProfile(tbUsernameRecover.Text)
3
4 ' Define user name
5 Dim name As String = userProfile.Personal.Name
6
7 ' Define user email address
8 Dim email As String = user.Email
9
10 ' Reset user password
11 Dim newPassword As String = user.ResetPassword()
12
13 ' Create new mail message
14 Dim message As New System.Net.Mail.MailMessage
15
16 ' Define mail message properties
17 With message
18
19 ' Define mail message properties
20 .Body = Resources.Email.PasswordReset_Body & newPassword
21 .From = New
System.Net.Mail.MailAddress(ConfigurationManager.A ppSettings("Email.NoReply.Address"),
ConfigurationManager.AppSettings("Email.NoReply.Na me"))
22 .IsBodyHtml = False
23 .Subject = Resources.Email.PasswordReset_Subject
24 .To.Add(New System.Net.Mail.MailAddress(email, name))
25
26 End With
27
28 ' Create and define the SMTP client
29 Dim smtpClient As New System.Net.Mail.SmtpClient
30
31 ' Get mailSettings section from web.config
32 Dim mailSettings As
System.Net.Configuration.MailSettingsSectionGroup =
ConfigurationManager.GetSection("system.net/mailSettings")
33
34 ' Define smtp client properties
35 If Not mailSettings Is Nothing Then
36 With smtpClient
37 .Port = mailSettings.Smtp.Network.Port
38 .Host = mailSettings.Smtp.Network.Host
39 .Credentials = New
System.Net.NetworkCredential(mailSettings.Smtp.Net work.UserName,
mailSettings.Smtp.Network.Password)
40 End With
41 End If
42
43 ' Send the mail message
44 Try
45
46 ' Send the mail message
47 smtpClient.Send(message)
48
49 Catch ex As Exception
50
51 Response.Write(ex.ToString)
52
53 End Try

And in my web.config file I have:

<system.net>
<mailSettings>
<smtp deliveryMethod="Network">
<network defaultCredentials="true"
host="mail.mydomain.com" password="pass" port="25"
userName="ga*****@mydomain.com"/>
</smtp>
</mailSettings>
</system.net>

This email account exists and it is working!

Could someone tell me what am I doing wrong here?

Thanks,

Miguel

Jan 5 '07 #1
8 7264
I have been trying to solve this and it seems that mailSettings in line
32 is an empty object so lines 36 to 40 are not running.

Any idea?

Thanks,

Miguel

shapper wrote:
Hello,

I am trying to send an email using Asp.Net 2.0.

I am getting the following 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)

The strange thing is that the email box really exists.

My code is as follows:

1 ' Define user profile
2 Dim userProfile As ProfileCommon =
Profile.GetProfile(tbUsernameRecover.Text)
3
4 ' Define user name
5 Dim name As String = userProfile.Personal.Name
6
7 ' Define user email address
8 Dim email As String = user.Email
9
10 ' Reset user password
11 Dim newPassword As String = user.ResetPassword()
12
13 ' Create new mail message
14 Dim message As New System.Net.Mail.MailMessage
15
16 ' Define mail message properties
17 With message
18
19 ' Define mail message properties
20 .Body = Resources.Email.PasswordReset_Body & newPassword
21 .From = New
System.Net.Mail.MailAddress(ConfigurationManager.A ppSettings("Email.NoReply.Address"),
ConfigurationManager.AppSettings("Email.NoReply.Na me"))
22 .IsBodyHtml = False
23 .Subject = Resources.Email.PasswordReset_Subject
24 .To.Add(New System.Net.Mail.MailAddress(email, name))
25
26 End With
27
28 ' Create and define the SMTP client
29 Dim smtpClient As New System.Net.Mail.SmtpClient
30
31 ' Get mailSettings section from web.config
32 Dim mailSettings As
System.Net.Configuration.MailSettingsSectionGroup =
ConfigurationManager.GetSection("system.net/mailSettings")
33
34 ' Define smtp client properties
35 If Not mailSettings Is Nothing Then
36 With smtpClient
37 .Port = mailSettings.Smtp.Network.Port
38 .Host = mailSettings.Smtp.Network.Host
39 .Credentials = New
System.Net.NetworkCredential(mailSettings.Smtp.Net work.UserName,
mailSettings.Smtp.Network.Password)
40 End With
41 End If
42
43 ' Send the mail message
44 Try
45
46 ' Send the mail message
47 smtpClient.Send(message)
48
49 Catch ex As Exception
50
51 Response.Write(ex.ToString)
52
53 End Try

And in my web.config file I have:

<system.net>
<mailSettings>
<smtp deliveryMethod="Network">
<network defaultCredentials="true"
host="mail.mydomain.com" password="pass" port="25"
userName="ga*****@mydomain.com"/>
</smtp>
</mailSettings>
</system.net>

This email account exists and it is working!

Could someone tell me what am I doing wrong here?

Thanks,

Miguel
Jan 5 '07 #2
"shapper" <md*****@gmail.comwrote in message
news:11**********************@42g2000cwt.googlegro ups.com...
I am getting the following 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)
http://www.aspnix.com/forums/thread/9158.aspx
Jan 5 '07 #3
Hi,

As far as I understood that article I am not doing anything wrong:

1. The from email address and the SMTP email address defined on the
web.config both exist.
2. In my web.config SMTP configuration I have the username and password
so SMTP authentication is possible.

What could be wrong then?

Thanks,
Miguel

Mark Rae wrote:
"shapper" <md*****@gmail.comwrote in message
news:11**********************@42g2000cwt.googlegro ups.com...
I am getting the following 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)

http://www.aspnix.com/forums/thread/9158.aspx
Jan 5 '07 #4
There is a thing called "authentication mode" for email sending (smtp).

None
Basic
SSL

It looks like you're using userName and password.

<system.net>

<mailSettings>
<smtp from="yo**@email.com">
<network host="smtp-server.rr.com" password=""
userName="my*******@rr.com" />
</smtp>
</mailSettings>

</system.net>

I don't know what the <tagis for using SSL, maybe research that. Or maybe
remove userName and password attributes to kick in "None". (I'm
guessing/experimenting here, I don't know which combo's affect the
authentication mode).

I actually have a better solution at:

2/8/2006
Smarter Email/Smtp setup with DotNet Configuration Sections (1.1 and 2.0)
http://sholliday.spaces.live.com/blog/

"shapper" <md*****@gmail.comwrote in message
news:11*********************@42g2000cwt.googlegrou ps.com...
I have been trying to solve this and it seems that mailSettings in line
32 is an empty object so lines 36 to 40 are not running.

Any idea?

Thanks,

Miguel

shapper wrote:
Hello,

I am trying to send an email using Asp.Net 2.0.

I am getting the following 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)

The strange thing is that the email box really exists.

My code is as follows:

1 ' Define user profile
2 Dim userProfile As ProfileCommon =
Profile.GetProfile(tbUsernameRecover.Text)
3
4 ' Define user name
5 Dim name As String = userProfile.Personal.Name
6
7 ' Define user email address
8 Dim email As String = user.Email
9
10 ' Reset user password
11 Dim newPassword As String = user.ResetPassword()
12
13 ' Create new mail message
14 Dim message As New System.Net.Mail.MailMessage
15
16 ' Define mail message properties
17 With message
18
19 ' Define mail message properties
20 .Body = Resources.Email.PasswordReset_Body & newPassword
21 .From = New
System.Net.Mail.MailAddress(ConfigurationManager.A ppSettings("Email.NoReply.
Address"),
ConfigurationManager.AppSettings("Email.NoReply.Na me"))
22 .IsBodyHtml = False
23 .Subject = Resources.Email.PasswordReset_Subject
24 .To.Add(New System.Net.Mail.MailAddress(email, name))
25
26 End With
27
28 ' Create and define the SMTP client
29 Dim smtpClient As New System.Net.Mail.SmtpClient
30
31 ' Get mailSettings section from web.config
32 Dim mailSettings As
System.Net.Configuration.MailSettingsSectionGroup =
ConfigurationManager.GetSection("system.net/mailSettings")
33
34 ' Define smtp client properties
35 If Not mailSettings Is Nothing Then
36 With smtpClient
37 .Port = mailSettings.Smtp.Network.Port
38 .Host = mailSettings.Smtp.Network.Host
39 .Credentials = New
System.Net.NetworkCredential(mailSettings.Smtp.Net work.UserName,
mailSettings.Smtp.Network.Password)
40 End With
41 End If
42
43 ' Send the mail message
44 Try
45
46 ' Send the mail message
47 smtpClient.Send(message)
48
49 Catch ex As Exception
50
51 Response.Write(ex.ToString)
52
53 End Try

And in my web.config file I have:

<system.net>
<mailSettings>
<smtp deliveryMethod="Network">
<network defaultCredentials="true"
host="mail.mydomain.com" password="pass" port="25"
userName="ga*****@mydomain.com"/>
</smtp>
</mailSettings>
</system.net>

This email account exists and it is working!

Could someone tell me what am I doing wrong here?

Thanks,

Miguel

Jan 5 '07 #5
I changed defaultCredentials="true" to defaultCredentials="false" and
now it is working fine.

Thanks,
Miguel

sloan wrote:
There is a thing called "authentication mode" for email sending (smtp).

None
Basic
SSL

It looks like you're using userName and password.

<system.net>

<mailSettings>
<smtp from="yo**@email.com">
<network host="smtp-server.rr.com" password=""
userName="my*******@rr.com" />
</smtp>
</mailSettings>

</system.net>

I don't know what the <tagis for using SSL, maybe research that. Or maybe
remove userName and password attributes to kick in "None". (I'm
guessing/experimenting here, I don't know which combo's affect the
authentication mode).

I actually have a better solution at:

2/8/2006
Smarter Email/Smtp setup with DotNet Configuration Sections (1.1 and 2.0)
http://sholliday.spaces.live.com/blog/

"shapper" <md*****@gmail.comwrote in message
news:11*********************@42g2000cwt.googlegrou ps.com...
I have been trying to solve this and it seems that mailSettings in line
32 is an empty object so lines 36 to 40 are not running.

Any idea?

Thanks,

Miguel

shapper wrote:
Hello,
>
I am trying to send an email using Asp.Net 2.0.
>
I am getting the following 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)
>
The strange thing is that the email box really exists.
>
My code is as follows:
>
1 ' Define user profile
2 Dim userProfile As ProfileCommon =
Profile.GetProfile(tbUsernameRecover.Text)
3
4 ' Define user name
5 Dim name As String = userProfile.Personal.Name
6
7 ' Define user email address
8 Dim email As String = user.Email
9
10 ' Reset user password
11 Dim newPassword As String = user.ResetPassword()
12
13 ' Create new mail message
14 Dim message As New System.Net.Mail.MailMessage
15
16 ' Define mail message properties
17 With message
18
19 ' Define mail message properties
20 .Body = Resources.Email.PasswordReset_Body & newPassword
21 .From = New
>
System.Net.Mail.MailAddress(ConfigurationManager.A ppSettings("Email.NoReply.
Address"),
ConfigurationManager.AppSettings("Email.NoReply.Na me"))
22 .IsBodyHtml = False
23 .Subject = Resources.Email.PasswordReset_Subject
24 .To.Add(New System.Net.Mail.MailAddress(email, name))
25
26 End With
27
28 ' Create and define the SMTP client
29 Dim smtpClient As New System.Net.Mail.SmtpClient
30
31 ' Get mailSettings section from web.config
32 Dim mailSettings As
System.Net.Configuration.MailSettingsSectionGroup =
ConfigurationManager.GetSection("system.net/mailSettings")
33
34 ' Define smtp client properties
35 If Not mailSettings Is Nothing Then
36 With smtpClient
37 .Port = mailSettings.Smtp.Network.Port
38 .Host = mailSettings.Smtp.Network.Host
39 .Credentials = New
System.Net.NetworkCredential(mailSettings.Smtp.Net work.UserName,
mailSettings.Smtp.Network.Password)
40 End With
41 End If
42
43 ' Send the mail message
44 Try
45
46 ' Send the mail message
47 smtpClient.Send(message)
48
49 Catch ex As Exception
50
51 Response.Write(ex.ToString)
52
53 End Try
>
And in my web.config file I have:
>
<system.net>
<mailSettings>
<smtp deliveryMethod="Network">
<network defaultCredentials="true"
host="mail.mydomain.com" password="pass" port="25"
userName="ga*****@mydomain.com"/>
</smtp>
</mailSettings>
</system.net>
>
This email account exists and it is working!
>
Could someone tell me what am I doing wrong here?
>
Thanks,
>
Miguel
Jan 5 '07 #6
"shapper" <md*****@gmail.comwrote in message
news:11**********************@42g2000cwt.googlegro ups.com...
What could be wrong then?
You're using defaultCredentials=true, which (I think) is overriding the
other settings...
Jan 5 '07 #7
Yes, I just got that a few minutes ago. :-)

Thanks,
Miguel

Mark Rae wrote:
"shapper" <md*****@gmail.comwrote in message
news:11**********************@42g2000cwt.googlegro ups.com...
What could be wrong then?

You're using defaultCredentials=true, which (I think) is overriding the
other settings...
Jan 5 '07 #8
Ok...

My guess would be that ... setting that to false.... reverts it back to NONE
authentication mode.
"shapper" <md*****@gmail.comwrote in message
news:11**********************@51g2000cwl.googlegro ups.com...
I changed defaultCredentials="true" to defaultCredentials="false" and
now it is working fine.

Thanks,
Miguel

sloan wrote:
There is a thing called "authentication mode" for email sending (smtp).

None
Basic
SSL

It looks like you're using userName and password.

<system.net>

<mailSettings>
<smtp from="yo**@email.com">
<network host="smtp-server.rr.com" password=""
userName="my*******@rr.com" />
</smtp>
</mailSettings>

</system.net>

I don't know what the <tagis for using SSL, maybe research that. Or
maybe
remove userName and password attributes to kick in "None". (I'm
guessing/experimenting here, I don't know which combo's affect the
authentication mode).

I actually have a better solution at:

2/8/2006
Smarter Email/Smtp setup with DotNet Configuration Sections (1.1 and
2.0)
http://sholliday.spaces.live.com/blog/

"shapper" <md*****@gmail.comwrote in message
news:11*********************@42g2000cwt.googlegrou ps.com...
I have been trying to solve this and it seems that mailSettings in
line
32 is an empty object so lines 36 to 40 are not running.
>
Any idea?
>
Thanks,
>
Miguel
>
shapper wrote:
Hello,

I am trying to send an email using Asp.Net 2.0.

I am getting the following 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)

The strange thing is that the email box really exists.

My code is as follows:

1 ' Define user profile
2 Dim userProfile As ProfileCommon =
Profile.GetProfile(tbUsernameRecover.Text)
3
4 ' Define user name
5 Dim name As String = userProfile.Personal.Name
6
7 ' Define user email address
8 Dim email As String = user.Email
9
10 ' Reset user password
11 Dim newPassword As String = user.ResetPassword()
12
13 ' Create new mail message
14 Dim message As New System.Net.Mail.MailMessage
15
16 ' Define mail message properties
17 With message
18
19 ' Define mail message properties
20 .Body = Resources.Email.PasswordReset_Body &
newPassword
21 .From = New
System.Net.Mail.MailAddress(ConfigurationManager.A ppSettings("Email.NoReply.
Address"),
ConfigurationManager.AppSettings("Email.NoReply.Na me"))
22 .IsBodyHtml = False
23 .Subject = Resources.Email.PasswordReset_Subject
24 .To.Add(New System.Net.Mail.MailAddress(email, name))
25
26 End With
27
28 ' Create and define the SMTP client
29 Dim smtpClient As New System.Net.Mail.SmtpClient
30
31 ' Get mailSettings section from web.config
32 Dim mailSettings As
System.Net.Configuration.MailSettingsSectionGroup =
ConfigurationManager.GetSection("system.net/mailSettings")
33
34 ' Define smtp client properties
35 If Not mailSettings Is Nothing Then
36 With smtpClient
37 .Port = mailSettings.Smtp.Network.Port
38 .Host = mailSettings.Smtp.Network.Host
39 .Credentials = New
System.Net.NetworkCredential(mailSettings.Smtp.Net work.UserName,
mailSettings.Smtp.Network.Password)
40 End With
41 End If
42
43 ' Send the mail message
44 Try
45
46 ' Send the mail message
47 smtpClient.Send(message)
48
49 Catch ex As Exception
50
51 Response.Write(ex.ToString)
52
53 End Try

And in my web.config file I have:

<system.net>
<mailSettings>
<smtp deliveryMethod="Network">
<network defaultCredentials="true"
host="mail.mydomain.com" password="pass" port="25"
userName="ga*****@mydomain.com"/>
</smtp>
</mailSettings>
</system.net>

This email account exists and it is working!

Could someone tell me what am I doing wrong here?

Thanks,

Miguel
>

Jan 5 '07 #9

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

Similar topics

11
12039
by: Google Mike | last post by:
I've got RH9 Linux with default PHP. Is there a way to send email on Linux to an Exchange Server from PHP and/or other tools when there is *NOT* SMTP access? Has anyone figured out a way to...
40
11781
by: ian | last post by:
Hi, I'm a newbie (oh no I can here you say.... another one...) How can I get Python to send emails using the default windows email client (eg outlook express)? I thought I could just do the...
0
3673
by: David Burson | last post by:
Hi, I have a VB.NET windows app that needs to automatically send a simple text email when my users run a new version of the app for the first time. I thought this would be simple, but after...
9
4293
by: Bob Jones | last post by:
We have developed a commercial ASP.net application (personal nutrition management and tracking); we want to send smtp email from within it. For our development box, we use WinXP Pro, IIS 5.5,...
3
4536
by: Gerard | last post by:
Hello I have created a windows service to monitor a database, it starts some checks when a timer elapses. The checks send emails depending on their findings. My issue is that when I created a...
14
9105
by: supz | last post by:
Hi, I use the standard code given below to send an email from an ASP.NET web form. The code executes fine but no Email is sent. All emails get queued in the Inetpub mail queue. I'm using my...
9
77407
by: Mahernoz | last post by:
Can i send an email from JavaScript? Is it possible? If yes please the code to send email using javascript...
2
5620
by: Malli mindwave | last post by:
Hi, We are using the yahoowebHostiing service for my company website, In that one screen of the SendComments/FeedBack section is there, I'm basically dot.net develeoper ,but yahoowebhosting not...
5
2148
by: Mike | last post by:
I have a page with a textbox that a user can enter in mutliple email addresses such as: user1@yahoo.com;user2@yahoo.com;user3@gmail.com; and so on, I then have a foreach loop to get all of the...
0
7115
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...
0
7321
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,...
0
7377
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...
1
7036
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...
0
7489
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...
0
5624
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,...
0
4705
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1547
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
414
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.