I was trying to have an email sent when the page loads but having some
trouble with it.
Our server is an IIS 6.0 with Framework 2.0. It is set to windows
authentication (not anonymous).
I don't really know what I'm doing and so far my tests haven't been so good.
Here's the code I tried:
Dim test As New System.Net.Mail.SmtpClient
test.DeliveryMethod = Net.Mail.SmtpDeliveryMethod.Network
test.UseDefaultCredentials = True
test.Host = "mailserver"
test.Send("Jim Morrison", "in**************@domain.local", "Test Sub", "Test
Body")
The error message I get is:
The specified string is not in the form required for an e-mail address.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.
Exception Details: System.FormatException: The specified string is not in
the form required for an e-mail address.
Source Error:
Line 16: test.UseDefaultCredentials = True
Line 17: test.Host = "exfs"
Line 18: test.Send("Jim Morrison", "in**************@hhs.local",
"Test Sub", "Test Body")
Line 19:
Line 20: End Sub
Source File: c:\inetpub\wwwroot\tests\winauth1.aspx.vb Line: 18
Stack Trace:
[FormatException: The specified string is not in the form required for an
e-mail address.]
System.Net.Mime.MailBnfHelper.ReadMailAddress(Stri ng data, Int32& offset,
String& displayName) +872611
System.Net.Mail.MailAddress.ParseValue(String address) +245
System.Net.Mail.MailAddress..ctor(String address, String displayName,
Encoding displayNameEncoding) +87
System.Net.Mail.Message..ctor(String from, String to) +127
System.Net.Mail.MailMessage..ctor(String from, String to) +117
System.Net.Mail.SmtpClient.Send(String from, String recipients, String
subject, String body) +31
tests_winauth1.Page_Load(Object sender, EventArgs e) in
c:\inetpub\wwwroot\tests\winauth1.aspx.vb:18
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +47
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1061
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.42; ASP.NET
Version:2.0.50727.42
TIA,
Jim 8 5977
> The error message I get is: The specified string is not in the form required for an e-mail address.
That probably means your 'for' field (first parameter to test.Send) is
not a correctly formed email address; use (e.g.)
test.Send("ji*@test.domain", whatever...) instead. Other than that it
should work (unless your Exchange server requires extra
authentication).
"Paul Henderson" <pa***********@pittville.demon.co.uk> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com... The error message I get is:
The specified string is not in the form required for an e-mail address.
That probably means your 'for' field (first parameter to test.Send) is not a correctly formed email address; use (e.g.) test.Send("ji*@test.domain", whatever...) instead. Other than that it should work (unless your Exchange server requires extra authentication).
You're right, I had to change it to a valid email address. When I did, I got
a new error:
Client does not have permission to submit mail to this server. The server
response was: 5.7.3 Client was not authenticated.
I don't know how I would authenticate it properly. Do you or anyone else
reading this have any experience with domain authentication? I read this
article but I couldn't follow it very well; one reason is that the coding
examples were in C# and I only use VB. I tried some of it (see code below): http://msdn.microsoft.com/library/de...lained0001.asp
The full code of my email attempt is this:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Load
Dim WinID As WindowsIdentity = HttpContext.Current.User.Identity
Dim ctx As WindowsImpersonationContext = Nothing
ctx = WinID.Impersonate()
Dim test As New System.Net.Mail.SmtpClient
test.DeliveryMethod = Net.Mail.SmtpDeliveryMethod.Network
test.UseDefaultCredentials = True
test.Host = "exfs"
test.Send("jm*******@hhs.local", "in**************@hhs.local", "Test
Sub", "Test Body")
End Sub
> I don't know how I would authenticate it properly. Do you or anyone else reading this have any experience with domain authentication?
If you have IIS set to do Integrated Windows Authentication, and
ASP.NET set up to impersonate for the relevant area of the application
(<identity impersonate="true" /> or similar) in web.config, then the
page should automatically run under the impersonation context of the
requesting user, and so you shouldn't need to do what you are with
WindowsIdentity.Impersonate (effectively, by passing
HttpContext.Current.User.Identity, you are telling it to impersonate
whoever is being impersonated, i.e. to do nothing). I should also
perhaps point out that you should stop the impersonation (using Revert)
at the end of the sub, or other code could start failing as it's
running under a strange user context.
So, check that your web.config is set up to impersonate, and also
perhaps check that WindowsIdentity.GetCurrent().Name matches the
username of the connected domain user. If both are fine, then your
Exchange server is likely set up *particularly* strangely, and isn't
just using Kerberos (integrated) authentication, but needs some other
credentials
"Paul Henderson" <pa***********@pittville.demon.co.uk> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com... I don't know how I would authenticate it properly. Do you or anyone else reading this have any experience with domain authentication?
If you have IIS set to do Integrated Windows Authentication, and ASP.NET set up to impersonate for the relevant area of the application (<identity impersonate="true" /> or similar) in web.config, then the page should automatically run under the impersonation context of the requesting user, and so you shouldn't need to do what you are with WindowsIdentity.Impersonate (effectively, by passing HttpContext.Current.User.Identity, you are telling it to impersonate whoever is being impersonated, i.e. to do nothing). I should also perhaps point out that you should stop the impersonation (using Revert) at the end of the sub, or other code could start failing as it's running under a strange user context.
So, check that your web.config is set up to impersonate, and also perhaps check that WindowsIdentity.GetCurrent().Name matches the username of the connected domain user. If both are fine, then your Exchange server is likely set up *particularly* strangely, and isn't just using Kerberos (integrated) authentication, but needs some other credentials
I went into my web.config file in the root directory and added what you
listed, so now my web config looks like this:
<!-- Web.Config Configuration File -->
<configuration>
<system.web>
<identity impersonate="true" />
<customErrors mode="Off"/>
<compilation debug="true"/>
</system.web>
</configuration>
I also simplified my aspx.vb code to this:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Try
Dim test As New System.Net.Mail.SmtpClient
test.Host = "exfs"
test.Send("jm*******@hhs.local", "in**************@hhs.local",
"Test Sub", "Test Body")
Catch ex As Exception
Response.Write(HttpContext.Current.User.Identity.N ame.ToString)
End Try
End Sub
The exception is still thrown because the catch appears, which does show my
current AD logon (HHS\jmorrison).
Our exchange server, which is an Exchange 2000 Standard, is set up basic. We
haven't made any unusual changes to it. In fact, I can't think of any
changes made at all after its initial install.
Our IIS server (IIS 6.0), has authentication set to Integrated Windows
Authentication and anonymous access disabled. Digest Authentication for
Windows Domain Servers is not checked though. Would that matter?
So, when I load the webpage (called winauth1.aspx) into my web browser from
a computer on our domain (my workstation), it should use my username to
authenticate to our exchange server, right? But it doesn't for some reason.
Our exchange server is not connected to the outside world. It just acts as
our mail server for our LAN.
Thanks.
> The exception is still thrown because the catch appears, which does show my current AD logon (HHS\jmorrison).
Hmm, that's interesting [I'm guessing you've checked it's still the
*same* exception].
Digest Authentication for Windows Domain Servers is not checked though Would that matter?
It shouldn't, no; it just provides a less secure alternative when
Integrated authentication is not appropriate, but you don't need it
here.
So, when I load the webpage (called winauth1.aspx) into my web browser from a computer on our domain (my workstation), it should use my username to authenticate to our exchange server, right? But it doesn't for some reason.
Yes, it should (basically). I suspect that it is sending the
credentials now, but the Exchange server is not liking it; the code you
have now is 'correct', as far as I can see. You might want to take a
look at the Exchange server's settings, and see what sort of
authentication it's expecting (e.g. if it wants plaintext [basic] or
digest authentication, then ASP probably won't be able to talk to it
directly like this; you should however be able to tell it to use
Integrated authentication itself, which it should really be doing
anyway).
Other than that, I don't think I can help, but do post again if any new
evidence comes to light...
"Paul Henderson" <pa***********@pittville.demon.co.uk> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com... The exception is still thrown because the catch appears, which does show my current AD logon (HHS\jmorrison).
Hmm, that's interesting [I'm guessing you've checked it's still the *same* exception].
Digest Authentication for Windows Domain Servers is not checked though Would that matter?
It shouldn't, no; it just provides a less secure alternative when Integrated authentication is not appropriate, but you don't need it here.
So, when I load the webpage (called winauth1.aspx) into my web browser from a computer on our domain (my workstation), it should use my username to authenticate to our exchange server, right? But it doesn't for some reason.
Yes, it should (basically). I suspect that it is sending the credentials now, but the Exchange server is not liking it; the code you have now is 'correct', as far as I can see. You might want to take a look at the Exchange server's settings, and see what sort of authentication it's expecting (e.g. if it wants plaintext [basic] or digest authentication, then ASP probably won't be able to talk to it directly like this; you should however be able to tell it to use Integrated authentication itself, which it should really be doing anyway).
Other than that, I don't think I can help, but do post again if any new evidence comes to light...
I checked the properties of the SMTP virtual server on the exchange server.
The authentication was set to Basic and Integrated Windows Authentication. I
unchecked the Basic auth and tried again and I sitll got the same error.
What if we tried coding a different way, like providing a specific set of
credentials in the VB code? I was going to try to use the credentials
property,( ie: test.credentials) but I couldn't figure out how to use it, or
even if I should try.
Thanks for your persistant help.
> What if we tried coding a different way, like providing a specific set of credentials in the VB code? I was going to try to use the credentials property,( ie: test.credentials) but I couldn't figure out how to use it, or even if I should try.
Yes, there's a chance that might work. You need to create new
System.Net.NetworkCredential object and set test.Credentials equal to
it, and also to turn off test.UseDefaultCredentials. The constructor
for NetworkCredential takes three parameters: username, password,
domain. Then, it should use those credentials for the authentication.
That should also work if your Exchange server is switched to Basic
authentication only; it might be worthwhile using that rather than
Integrated for a test to see whether it works any better.
Paul Henderson wrote: What if we tried coding a different way, like providing a specific set of credentials in the VB code? I was going to try to use the credentials property,( ie: test.credentials) but I couldn't figure out how to use it, or even if I should try.
Yes, there's a chance that might work. You need to create new System.Net.NetworkCredential object and set test.Credentials equal to it, and also to turn off test.UseDefaultCredentials. The constructor for NetworkCredential takes three parameters: username, password, domain. Then, it should use those credentials for the authentication. That should also work if your Exchange server is switched to Basic authentication only; it might be worthwhile using that rather than Integrated for a test to see whether it works any better.
Success Paul! Here's the code that did the trick:
Dim test As New System.Net.Mail.SmtpClient
Dim nco As New System.Net.NetworkCredential("webapplications",
"password", "domain")
test.Credentials = nco
test.Host = "exfs"
test.Send("we*************@domain.local", "te******@domain.local", "Test
Subject", "Test Message Body")
Thanks for the help!
Jim This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Brian Henry |
last post by:
Does anyone know how to send an email to an internal exchange server
(internal email only, how you can send email to a username in active
directory in exchange with out a domain (@domain.com) after...
|
by: Elliot |
last post by:
The following code works when sending to an email address that resides
on our Exchange domain. However, when trying to send to an External
domain it does not work. The folling is the "doesn't work"...
|
by: Brian Henry |
last post by:
I want my app to send an email to users on the exchange server locally...
the email format internally is firstname_lastname which is the same as the
domain user name of course..when someone clicks...
|
by: Kevin Swanson |
last post by:
First, apologies for cross-posting. I posted this message originally in
exchange2000.development, but it looks like that's an unmanaged group. At
least it doesn't show up in the list when looking...
|
by: tshad |
last post by:
I have a W2003 server running my website and I am trying to set up my pages
to send email using System.Web.Mail.
I have pages running on this machine using CDONTS that work fine.
I am using...
|
by: Jim in Arizona |
last post by:
I've made an application that is a computer problems (tickets) system. The
employee goes to a web page and posts the comptuer problem they're having.
Then, the IS staff goes to another webpage...
|
by: B-Dog |
last post by:
I've built a small app that sends mail through our ISP's SMTP server but
when I try to send through my local exchange server I get CDO error. Does
webmail use SMTP or does it strictly rely on...
|
by: D. Patrick |
last post by:
I need to duplicate the functionality of a java applet, and how it connects
to a remote server. But, I don't have the protocol information or the java
source code which was written years ago. ...
|
by: Jack |
last post by:
Hi,
I am still new to .NET so, i'm sorry if my question is a bit too simple :-)
I would like to know what is the "best-practice-way" of sending email from
asp.net (VbScript). I want to make a...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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...
|
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,...
|
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...
| |