Click here to Skip to main content
15,938,848 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi guys
please help me I am failing to send an email in asp.net. my service provider does not allow the use of smtp, so i have to post my form to a page they gave me so that they can forward it to my email.
i have something like this:

HTML
<form method="post" action="http://their_page.com/mailto/mailto.pl">
<input type="hidden" name="followup-page" value="http://my_follo_page.com/mailto/confirm.html">
<input type="hidden" name="recip" value="email@domain.co.za">
<input type="hidden" name="subj" value="Feedback Form"> 
<input type="hidden" name="from" value="email@domain.co.za"> 
<input type="hidden" name="body"


How can i do this in ASP.net, i need this because my website is developed in ASP?
when i do it html, it works fine but doesnt work with an ASP.NET page (nothing happens when i click submit ) and i cannot use HTML because of the look, i cant use the ASP.NET master page with html page.


The other thing, how can i modify my register.asp page to send an confirmation email when somebody register? i only know how to send email with smtp, how can i post the username and email to that server page? this is my register.aspx.cs:
C#
namespace WebApplication1.Account
{
    public partial class Register : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            RegisterUser.ContinueDestinationPageUrl = Request.QueryString["ReturnUrl"];
        }
        protected void RegisterUser_CreatedUser(object sender, EventArgs e)
        {
           MembershipUser newUser = Membership.GetUser(RegisterUser.UserName);
            Guid newUserID = (Guid)newUser.ProviderUserKey;
            string urlBase = Request.Url.GetLeftPart(UriPartial.Authority) + Request.ApplicationPath;
            string verifyUrl = "VerifyNewUser.aspx?ID=" + newUserID.ToString();
            string fullPath = urlBase + verifyUrl;
            string appPath= Request.PhysicalApplicationPath;
           StreamReader sr = new StreamReader(appPath + "EmailTemplates/VerifyNewUser.txt");
           MailMessage message = new MailMessage();
            message.IsBodyHtml = true;
           message.From = new MailAddress("studentcompanionsa@gmail.com","Student Companion");
            message.To.Add( new MailAddress(RegisterUser.Email));
           message.CC.Add(new MailAddress("membership@studentcompanion.co.za"));
            message.Subject = "New User Registration";
            message.Body = sr.ReadToEnd();
            sr.Close();
            message.Body = message.Body.Replace("<%UserName%>", RegisterUser.UserName);
            message.Body = message.Body.Replace("<%VerificationUrl%>", fullPath);
            SmtpClient client = new SmtpClient();
           client.EnableSsl = true;
           client.Send(message);
            //FormsAuthentication.SetAuthCookie(RegisterUser.UserName, false /* createPersistentCookie */);
            string continueUrl = RegisterUser.ContinueDestinationPageUrl;
            if (String.IsNullOrEmpty(continueUrl))
            {
                //continueUrl = "~/";
                continueUrl = "~/RegisterEmailNotification.aspx";
            }
            Response.Redirect(continueUrl);
            
        }
    }
}




THANK YOU VERY MUCH.
Posted
Updated 12-Jun-20 1:29am
v2
Comments
David_Wimbley 27-Apr-13 21:16pm    
Your question does not make sense. Can you be a little more clear. For clarification, is all you need to do the following in Asp.Net?

A form that submits the posts the values so you can then send those values via email to your inbox?
katela 28-Apr-13 10:14am    
my webhosting company will forward the form to my inbox email.
they dont allow smtp.
jkirkerx 28-Apr-13 1:35am    
Just use a html submit button instead of a asp.net object button
katela 28-Apr-13 10:15am    
a html submit button works when inside an html page, but it seems not to work when i put it inside an asp.net page
David_Wimbley 28-Apr-13 13:14pm    
Can you improve your question to include your whole code snippet because you keep saying it works inside an html page but not an asp.net page...HTML is HTML is HTML. You can't have a page without HTML it doesn't matter if you are doing webforms, mvc, coldfusion, php, perl...a form is a form is a form.

Can you provide a full code snippet of your issue, what you are saying doesn't make sense.

To help on the first question, I think it would go something like this.

It's been a long time since I've written a form to submit to another form, it was in PHP, but this is my version of how to do it in asp.net, and retain the enter key submission.

You may have to rename the ID's of the textbox and take out the prefix txt_, I forget what the name attribute is for.

I took advantage of 4.0 clientIDMode as set the controls as static to maintain the proper name and id values.

<![CDATA[<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>]]>
 
Share this answer
 
To help on the first question, I think it would go something like this.

It's been a long time since I've written a form to submit to another form, it was in PHP, but this is my version of how to do it in asp.net, and retain the enter key submission.

You may have to rename the ID's of the textbox and take out the prefix txt_, I forget what the name attribute is for.

I took advantage of 4.0 clientIDMode as set the controls as static to maintain the proper name and id values.

<form id="form1" runat="server">
<div>
    <asp:panel id="panel_emailSubmit" runat="server" style="width: 350px; text-align: left;" defaultbutton="bt_Submit" clientidmode="Static" xmlns:asp="#unknown">
        <table cellpadding="0" cellspacing="0" border="0" style="width: 350px;">
            <tr>
                <td style="width: 350px; height: 96px; text-align: left;">
                    <asp:textbox runat="server" id="txt_recip" clientidmode="Static">email@domain.co.za</asp:textbox><br />
                    <asp:textbox runat="server" id="txt_subj" clientidmode="Static">Feedback Form</asp:textbox><br />
                    <asp:textbox runat="server" id="txt_from" clientidmode="Static">email@domain.co.za</asp:textbox><br />
                    <asp:textbox runat="server" id="txt_body" clientidmode="Static"></asp:textbox><br />
                </td>
            </tr>
            <tr>
                <td style="width: 350px; height: 46px; text-align: left;">
                    <asp:button runat="server" text="Button" id="bt_Submit" postbackurl="http://their_page.com/mailto/mailto.pl" clientidmode="Static" />
                </td>
            </tr>
            <tr>
                <td style="width: 350px; height: 0px; text-align: left;">
                    <input type="hidden" name="followup-page" value="http://my_follo_page.com/mailto/confirm.html" />
                </td>
            </tr>
        </table>
    </asp:panel>
</div>
</form>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900