have created a email page in my ASP.NET2 siteto send generic email . coded page in VB anyone at DASP have a clue as to what went wrong? Whystmp would reject my local test send. email page did not respond on debug?Used the ASP.NET exercise on sending email from an asp.net site. <%@ Page Language="VB" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> Protected Sub btnSend_Click(ByVal sender As Object, ByVal e As System.EventArgs) Dim mailMessage As System.Net.Mail.MailMessage = New System.Net.Mail.MailMessage() 'Get From address in web.config mailMessage.From = New System.Net.Mail.MailAddress(System.Configuration.ConfigurationManager.AppSettings("fromEmailAddress")) 'Configure mail message 'Set the From address with USER input line below 'mailMessage.From = New System.Net.Mail.MailAddress(txtFromAddress.Text.Trim()) mailMessage.To.Add(New System.Net.Mail.MailAddress(txtToAddress.Text.Trim())) mailMessage.Subject = txtSubject.Text.Trim() mailMessage.Body = txtBody.Text.Trim() Dim smtpClient As System.Net.Mail.SmtpClient = New System.Net.Mail.SmtpClient() smtpClient.Send(mailMessage) End Sub </script> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>SEND EMAIL</title> </head> <form id="form1" runat="server"> <div> <p>From:&nbsp; <asp:TextBox ID="txtFromAddress" runat="server" Columns="35" >[email protected]</asp:TextBox></p> <p>To:&nbsp; <asp:TextBox ID="txtToAddress" runat="server" Columns="35" /></p> <p>Subject:&nbsp; <asp:TextBox ID="txtSubject" runat="server" Columns="50" >NS/NSTI survey results</asp:TextBox></p> <p>Body:&nbsp; <asp:TextBox ID="txtBody" runat="server" Columns="75" TextMode="MultiLine" Rows="6" >Thank You...for your participation.</asp:TextBox></p> <p><asp:Button ID="btnSend" runat="server" Text="Send Mail" OnClick="btnSend_Click" /></p> </div> </form> </body> </html> I get the following error: No connection could be made because the target machine actively refused it 127.0.0.1:25 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: No connection could be made because the target machine actively refused it 127.0.0.1:25 Source Error: Code: Line 18: Dim smtpClient As System.Net.Mail.SmtpClient = New System.Net.Mail.SmtpClient() Line 19: Line 20: smtpClient.Send(mailMessage) Line 21: Line 22: End Sub
are you running this application on our server or your own computer? pls post the web.config as well. Bruce DiscountASP.NET www.DiscountASP.NET
I was running email page locally. I guess I should run it on remote. web config: <appSettings> <add key="fromEmailAddress" value="[email protected]"/> </appSettings> <connectionStrings> </system.web> <system.net> <mailSettings> <smtp from="[email protected]"> <network host="localhost" password="XXXXX" userName="XXXXXX" /> </smtp> </mailSettings> </system.net> </configuration>
if you are running this on your computer, localhost means your computer and apparently your computer doesn't have SMTP setup. If you run thison our server, it should connect to the SMTP server on the web server. Bruce DiscountASP.NET www.DiscountASP.NET