473,320 Members | 1,879 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Sending E-Mails from ASP.NET 2.0 page using System.Net.Mail

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 have written to send a test message:

-----Code Begins: Sensitive Information Replaced by [SOMETHING]-----
MailAddress from = new MailAddress([ADDRESS], [NAME]);
MailAddress to = new MailAddress([ADDRESS], [NAME]);
MailAddress copy = new MailAddress([ADDRESS], [NAME]);

MailMessage message = new MailMessage(from, to);
message.Subject = "Using the SmtpClient class.";
message.IsBodyHtml = true;
message.Body = @"Using this feature, you can send an e-mail message from an
application very easily.";
message.CC.Add(copy);

NetworkCredential authInfo = new NetworkCredential([USERNAME], [PASSWORD]);
SmtpClient client = new SmtpClient([DOMAIN NAME], 25);
client.UseDefaultCredentials = false;
client.Credentials = authInfo;
client.Send(message);
-----Code Ends-----

On Windows Server 2003, I have created an account and placed it in the SMTP
Users group and granted this group access to the SMTP Service. Under
Authentication, I checked Anonymous Access and Integrated Windows
Authentication. In the Outbound Security, I selected Integrated Windows
Authentication and provided the username and password for the account I
created previously.

When click submit to send the e-mail, this is the error I receive (sorry for
copying and pasting this long error report, but I don't know what is wrong):
-----Error Report Begins-----
Server Error in '/HfHv3' Application.
--------------------------------------------------------------------------------
An established connection was aborted by the software in your host machine
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.Net.Sockets.SocketException: An established
connection was aborted by the software in your host machine

Source Error:
Line 88: client.UseDefaultCredentials = false;
Line 89: client.Credentials = authInfo;
Line 90: client.Send(message);
Line 91:
Line 92: //try

Source File:
c:\Inetpub\wwwroot\HfHv3\intranet\board\mailinglis ts\sendemail.aspx.cs
Line: 90

Stack Trace:
[SocketException (0x2745): An established connection was aborted by the
software in your host machine]
System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot,
SocketAddress socketAddress) +1002146
System.Net.Sockets.Socket.InternalConnect(EndPoint remoteEP) +33
System.Net.ServicePoint.ConnectSocketInternal(Bool ean connectFailure,
Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState
state, IAsyncResult asyncResult, Int32 timeout, Exception& exception) +431

[WebException: Unable to connect to the remote server]
System.Net.ServicePoint.GetConnection(PooledStream PooledStream, Object
owner, Boolean async, IPAddress& address, Socket& abortSocket, Socket&
abortSocket6, Int32 timeout) +1447736
System.Net.PooledStream.Activate(Object owningObject, Boolean async,
Int32 timeout, GeneralAsyncDelegate asyncCallback) +190
System.Net.PooledStream.Activate(Object owningObject,
GeneralAsyncDelegate asyncCallback) +21
System.Net.ConnectionPool.GetConnection(Object owningObject,
GeneralAsyncDelegate asyncCallback, Int32 creationTimeout) +318
System.Net.Mail.SmtpConnection.GetConnection(Strin g host, Int32 port) +227
System.Net.Mail.SmtpTransport.GetConnection(String host, Int32 port) +316
System.Net.Mail.SmtpClient.GetConnection() +42
System.Net.Mail.SmtpClient.Send(MailMessage message) +1485

[SmtpException: Failure sending mail.]
System.Net.Mail.SmtpClient.Send(MailMessage message) +2074
sendemail.btnSend_Click(Object sender, EventArgs e) in
c:\Inetpub\wwwroot\HfHv3\intranet\board\mailinglis ts\sendemail.aspx.cs:90
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +105
System.Web.UI.WebControls.Button.RaisePostBackEven t(String eventArgument)
+107

System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) +33
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5102
-----Error Report Ends-----

Any help would be greatly appreciated!! Thanks a bunch!

Eric
Jan 29 '06 #1
1 8135
First thing:

You need to know if your external smtp server uses:
none
basic
or
ssl
authentication.

Here is my send an email code (2.0)

System.Net.Mail.SmtpClient email = new System.Net.Mail.SmtpClient();

email.Host = "smtp.myisp.com";

email.Port = 25; // Or 465 for smtp.gmail.com ... a SSL example

switch (serv.AuthenicationMethod) // this is MY enum...telling me which type
of authentication to use. this code won't compile, but you can see what i'm
doing // serv.AuthenicationMethod is My code... and will give you a compile
error

{

case AuthenticationType.None:

break;

case AuthenticationType.Basic:

email.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;

email.UseDefaultCredentials = false;

email.Credentials = new NetworkCredential(serv.SmtpUserName,
serv.SmtpUserPassword);

break;

case AuthenticationType.SSL:

email.EnableSsl = true;

email.Credentials = new NetworkCredential(serv.SmtpUserName,
serv.SmtpUserPassword);

//email.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network ;

break;

}

System.Net.Mail.MailMessage mailMsg = new
System.Net.Mail.MailMessage(fromAddress, toAddress, emailSubject, sBody);

mailMsg.IsBodyHtml = true;

email.Send(mailMsg);

I don't see email.EnableSsl = true; in your code.

...
Now, the second thing .... is that there is a difference between the Code
failing, and the server not Sending.

In Win 2000, sometimes C# code would work, but would get "stuck"

In win2000, the location was
C:\Inetpub\mailroot\Queue

I don't know about 2003 unforunately. But if there is an equivalent folder,
where emails are "dropped in" for sending, you can look there, and see if
there are entries in there.

The way I fixed this in win2000, was to set up a "smart host" under IIS,
under the email settings.
HTH a little.

Also check:
http://www.systemnetmail.com/default.aspx

"Eric Sheu" <Eric Sh**@discussions.microsoft.com> wrote in message
news:2E**********************************@microsof t.com...
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 have written to send a test message:

-----Code Begins: Sensitive Information Replaced by [SOMETHING]-----
MailAddress from = new MailAddress([ADDRESS], [NAME]);
MailAddress to = new MailAddress([ADDRESS], [NAME]);
MailAddress copy = new MailAddress([ADDRESS], [NAME]);

MailMessage message = new MailMessage(from, to);
message.Subject = "Using the SmtpClient class.";
message.IsBodyHtml = true;
message.Body = @"Using this feature, you can send an e-mail message from an application very easily.";
message.CC.Add(copy);

NetworkCredential authInfo = new NetworkCredential([USERNAME], [PASSWORD]); SmtpClient client = new SmtpClient([DOMAIN NAME], 25);
client.UseDefaultCredentials = false;
client.Credentials = authInfo;
client.Send(message);
-----Code Ends-----

On Windows Server 2003, I have created an account and placed it in the SMTP Users group and granted this group access to the SMTP Service. Under
Authentication, I checked Anonymous Access and Integrated Windows
Authentication. In the Outbound Security, I selected Integrated Windows
Authentication and provided the username and password for the account I
created previously.

When click submit to send the e-mail, this is the error I receive (sorry for copying and pasting this long error report, but I don't know what is wrong): -----Error Report Begins-----
Server Error in '/HfHv3' Application.
-------------------------------------------------------------------------- ------ An established connection was aborted by the software in your host machine
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.Net.Sockets.SocketException: An established
connection was aborted by the software in your host machine

Source Error:
Line 88: client.UseDefaultCredentials = false;
Line 89: client.Credentials = authInfo;
Line 90: client.Send(message);
Line 91:
Line 92: //try

Source File:
c:\Inetpub\wwwroot\HfHv3\intranet\board\mailinglis ts\sendemail.aspx.cs
Line: 90

Stack Trace:
[SocketException (0x2745): An established connection was aborted by the
software in your host machine]
System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot,
SocketAddress socketAddress) +1002146
System.Net.Sockets.Socket.InternalConnect(EndPoint remoteEP) +33
System.Net.ServicePoint.ConnectSocketInternal(Bool ean connectFailure,
Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Int32 timeout, Exception& exception) +431

[WebException: Unable to connect to the remote server]
System.Net.ServicePoint.GetConnection(PooledStream PooledStream, Object
owner, Boolean async, IPAddress& address, Socket& abortSocket, Socket&
abortSocket6, Int32 timeout) +1447736
System.Net.PooledStream.Activate(Object owningObject, Boolean async,
Int32 timeout, GeneralAsyncDelegate asyncCallback) +190
System.Net.PooledStream.Activate(Object owningObject,
GeneralAsyncDelegate asyncCallback) +21
System.Net.ConnectionPool.GetConnection(Object owningObject,
GeneralAsyncDelegate asyncCallback, Int32 creationTimeout) +318
System.Net.Mail.SmtpConnection.GetConnection(Strin g host, Int32 port) +227 System.Net.Mail.SmtpTransport.GetConnection(String host, Int32 port) +316 System.Net.Mail.SmtpClient.GetConnection() +42
System.Net.Mail.SmtpClient.Send(MailMessage message) +1485

[SmtpException: Failure sending mail.]
System.Net.Mail.SmtpClient.Send(MailMessage message) +2074
sendemail.btnSend_Click(Object sender, EventArgs e) in
c:\Inetpub\wwwroot\HfHv3\intranet\board\mailinglis ts\sendemail.aspx.cs:90
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +105
System.Web.UI.WebControls.Button.RaisePostBackEven t(String eventArgument) +107

System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePo
stBackEvent(String eventArgument) +7 System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) +33
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5102
-----Error Report Ends-----

Any help would be greatly appreciated!! Thanks a bunch!

Eric

Jan 30 '06 #2

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

Similar topics

3
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....
2
by: John Abel | last post by:
I have written a script that makes a telnet connection, runs various commands, and returns the output. That was the easy bit :) However, to close the session, I need to send ^] followed by quit. ...
4
by: knguyen | last post by:
This question may be ased before, but I couldn't find the answer searching the archive. Basically, I just want to send a hex number from one machine to the next: for example msg = "Length...
0
by: Walt | last post by:
I'm running SQL Server 2000 SP2 transactional replication. Periodically replication fails due to primary key errors. On investigation I find that the offending transaction is attempting to insert...
1
by: Butch | last post by:
Hi, I won't lie to you. I'm trying to get data from html source from a 3rd party website. I'm NOT interested in stealing code,hacking,sending spam or anything sinister like that. I just want the...
2
by: Chuck Marques | last post by:
I'm trying to implement sending an object through messaging, but I receive an error stating I can't deserialize the object. Any clues as to why. I have the following: <Serializable()> Public...
4
by: Winston Nimchan | last post by:
Hi: I'm currently developing a socket application and would like to precede the data being sent with a 4 byte message length header (bin4). Can anyone help Regards Winston
3
by: Juergen | last post by:
hi, I've got a problem sending floating point values to an corba server. With other datatyes like short or string it works fine. So having this idl file : module Example{ interface User{
0
by: Vajrala Narendra | last post by:
in the i got few problems please solve to help me also send information regarding email sending. Try Dim mailbody As String mailbody = "" mailbody =...
5
by: hurricane_number_one | last post by:
I am creating a simple server application, that will listen for incoming mouse coordinates and then move the mouse accordingly. So basically it's like a very simple VNC server without and screen...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.