SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Zealot pavanpuligandla's Avatar
    Join Date
    Sep 2008
    Location
    hyderabad
    Posts
    179
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    email webpage using asp.net

    Hii,
    i created Email this page button on my pages, when clicked it will ask for your name, email and recepient's name and email. if they were entered properly, then
    an email should be sent to recepient's email
    every thing is okay for me now as a newbiew C# programmer,
    but how can send the exact page's URL to email?
    we've to use sessions or wht?
    i did this in PHP as i'm a PHP developer..
    Many Thanks
    PHP Professional turned ASP.NET Professional

  2. #2
    SitePoint Zealot pavanpuligandla's Avatar
    Join Date
    Sep 2008
    Location
    hyderabad
    Posts
    179
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hii.
    i wrote code for sending an email using c#, but now my problem is,
    there will be "Email This Page" Link on each n every pages on my site,
    when a user is navigating page : http://xyz.com/abc.html, he would like to send this page link to a friend,
    i now need the exact URL of the page to be emailed.
    how to do this. can anyone please help me out..
    many thanks.
    PHP Professional turned ASP.NET Professional

  3. #3
    SitePoint Addict
    Join Date
    Feb 2005
    Location
    Clogland
    Posts
    322
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  4. #4
    SitePoint Zealot pavanpuligandla's Avatar
    Join Date
    Sep 2008
    Location
    hyderabad
    Posts
    179
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hii,
    i saw tht link, but as a newbiew .NET developer, i didnt understand tht.
    here is my code for tell a friend.
    everything is fine, but now i need to send the exact URL to recepient;s email.
    can anyone pls help me out..
    Code Csharp:
    using System;
    using System.Collections;
    using System.Configuration;
    using System.Data;
    using System.Linq;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Xml.Linq;
    using System.Web.Mail;
    using System.Drawing;
     
    namespace c.training
    {
        public partial class training_emailpage : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                //Uri url = Request.Url;
     
                //Response.Write(url);
            }
     
            protected void Button_Click(object sender, EventArgs e)
            {
                if (ValidateForm() == false)
                {
     
                    SendMail();
                }
     
            }
     
            private void SendMail()
            {
                try
                {
                    MailMessage mail = new MailMessage();
                    mail.To = this.ReceiverEmail.Text;
                    mail.From = this.YourEmail.Text;
                    mail.Subject = this.Subject.Text;
                    mail.Body = this.Message.Text + 
                        "/n"+
                    "<a target='_blank' href='" + "http://www.xyz.com/" + "'></a>" ;
                    SmtpMail.SmtpServer = "207.210.125.31";
                    SmtpMail.Send(mail);
                    lblStatus.Text = "Thank you! Your email with the page link has been sent.";
                    //Clear Form fields
                    ReceiverEmail.Text = " ";
                    YourEmail.Text = " ";
                    Subject.Text = " ";
                    Message.Text = " ";
                    YourName.Text= " ";
                    Required.Text = " ";
     
                }
     
                catch (Exception ex)
                {
                    lblStatus.Text = "Send Email Failed." + ex.Message;
                    Required.Text = " ";
                }
            }
            protected bool ValidateForm()
            {
                bool ErrorsFound;
                Required.Text = "* denotes required field";
                ErrorsFound = false;
     
                if (this.ReceiverEmail.Text == "" || this.ReceiverEmail.Text == null)
                {
                    this.lblReceiverEmail.Text = "*";
                    this.lblReceiverEmail.ForeColor = Color.Red;
                    ErrorsFound = true;
                }
                else
                {
                    this.lblReceiverEmail.Text = "";
                }
     
                if (this.YourEmail.Text == "" || this.YourEmail.Text == null)
                {
                    this.lblYourEmail.Text = "*";
                    this.lblYourEmail.ForeColor = Color.Red;
                    ErrorsFound = true;
                }
                else
                {
                    this.lblYourEmail.Text = "";
                }
     
                if (this.Message.Text == "" || this.Message.Text == null)
                {
                    this.lblMessage.Text = "*";
                    this.lblMessage.ForeColor = Color.Red;
                    ErrorsFound = true;
                }
                else
                {
                    this.lblMessage.Text = "";
                }
     
                if (this.YourName.Text == "" || this.YourName.Text == null)
                {
                    this.lblYourName.Text = "*";
                    this.lblYourName.ForeColor = Color.Red;
                    ErrorsFound = true;
                }
                else
                {
                    this.lblYourName.Text = "";
                }
     
     
     
                return ErrorsFound;
     
            }
     
         }
    }
    please do suggest me, many thanks again.
    PHP Professional turned ASP.NET Professional

  5. #5
    SitePoint Addict
    Join Date
    Feb 2005
    Location
    Clogland
    Posts
    322
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try this (I'm not able to test this at the moment, but you should get the idea)

    Code Csharp:
     
    mail.Body = this.Message.Text + "\n" +
      "<a target='_blank' href='" + Request.UrlReferrer.AbsoluteUri  + "'></a>" ;

  6. #6
    SitePoint Zealot pavanpuligandla's Avatar
    Join Date
    Sep 2008
    Location
    hyderabad
    Posts
    179
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try this (I'm not able to test this at the moment, but you should get the idea)

    Csharp Code:

    mail.Body = this.Message.Text + "\n" +
    "<a target='_blank' href='" + Request.UrlReferrer.AbsoluteUri
    Hii,
    i dont find any syntax errors, but unable to get email..i cannot see any emails in my inbox..thts the problem.
    thank you..
    PHP Professional turned ASP.NET Professional

  7. #7
    SitePoint Enthusiast
    Join Date
    Apr 2009
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    HTML Code:
     MailMessage msg = new MailMessage();
    
        msg.From = settings.SystemEmailAccount;
        msg.To = to;
        msg.Subject = subject;
        msg.Body = body;
    
        if(settings.SmtpAuthenticationRequired)
        {
         msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1" ); 
         msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", settings.SystemEmailAccount);
         msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", settings.SystemEmailAccountPassword);
        }
    
        if(settings.SmtpPort != 25)
        {
         msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", settings.SmtpPort.ToString());
        }
    
        if(settings.SmtpUseSSL)
        {
         msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpusessl", "1");
        }
    
        SmtpMail.SmtpServer = settings.SmtpServer;
        SmtpMail.Send(msg);
    
    Use the "MailMessage()"
    Tibet - information about the Tibet.
    Plan aTibet Travel Packages by train in July 2010!

  8. #8
    SitePoint Enthusiast
    Join Date
    May 2009
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    when you click the "Email to friend" button in the mail sending function just write mail.body = Request.UrlReferrer.AbsoluteUri.

    This will take the referal pages uri and send it in email. the receiver will get the link in mail and when he clicks on it he will be redirected to the page you want to show him. i think its a simple task.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •