Results 1 to 16 of 16

Thread: Send email with textbox values

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2008
    Posts
    268

    Question Send email with textbox values

    Hi i need to send a email to a constant mail id from my web page...
    The user need to give his name, email, mobile no, country allt he details want to be sent... with the message...

    From: Users email id
    Subject: Name, Mobile no, Country
    Message: Users comments from the message textbox

    and i need the configuration details for the smtp server....
    this is my first application in asp.net so let me have a clear idea on it...

    Thanks in advance....

  2. #2
    Frenzied Member Fishcake's Avatar
    Join Date
    Feb 2001
    Location
    Derby, UK
    Posts
    1,092

    Re: Send email with textbox values

    Sending email is reasonably easy with asp.net and is well described in this article.

    As for the configuration details of the server you will need those details off someone who administers your SMTP server.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2008
    Posts
    268

    Re: Send email with textbox values

    Quote Originally Posted by Fishcake
    Sending email is reasonably easy with asp.net and is well described in this article.

    As for the configuration details of the server you will need those details off someone who administers your SMTP server.
    Hi this is my code,

    is this correct...?

    protected void btnSubmit_Click(object sender, EventArgs e)
    {
    MailMessage mail = new MailMessage();

    mail.To = "[email protected]";

    mail.From = txtemail.Text;

    mail.Subject = txtname.Text;

    mail.Body = txtmessage.Text;

    SmtpMail.SmtpServer = "localhost";

    SmtpMail.Send(mail);

    }

    by checking this i'll have a error on the SmtpMail.Send(mail);

    tel me
    Last edited by mendhak; Jan 6th, 2009 at 06:57 AM.

  4. #4
    Junior Member
    Join Date
    Nov 2008
    Posts
    20

    Re: Send email with textbox values

    you need to actually fill in the "localhost" part, and for that it is very difficult to work with mail.From = txtEmail.Text, because different people use different smtp hosts.

    The easiest way (and probably the only way?) is to bypass this using a dummy email adress.

    For Example: For my school project I created a free G-Mail account [email protected].

    (Why gmail? 1. because it's free, 2. because it uses a different port than port 25, unlike most other free hosts, and part 25 is sometimes blocked by some people's ISP)

    Then in your code you say something like:
    Code:
    mail.From = "[email protected]"
    smtpClient sendMail = new smtpClient("smtp.gmail.com","587")
    SendMail.Credentials = New NetworkCredential("[email protected]", "yourpassword")
    //you need this enabled, because gmail needs to verfiy you are the owner of the account
    sendMail.Enablessl = true
    sendMail.send(mail)
    Forgive me if the syntax isn't 100% correct, I haven't got much time on hands right now.

    Edit: to have the persons adress, you can always put it in the replyTo properte (mail.ReplayTo = txtEmail.text)

  5. #5
    Frenzied Member Fishcake's Avatar
    Join Date
    Feb 2001
    Location
    Derby, UK
    Posts
    1,092

    Re: Send email with textbox values

    There's nothing that looks immediately wrong with your code.

    What error do you get?

    Is there an SMTP server running on the machine?
    As you are not authenticating with the smtp server is it set up to act as an open relay for your web server?

    NB. Best not to leave your email address in your post as it might get harvested for nasty spam.

  6. #6
    Frenzied Member Fishcake's Avatar
    Join Date
    Feb 2001
    Location
    Derby, UK
    Posts
    1,092

    Re: Send email with textbox values

    Quote Originally Posted by Arsenal
    you need to actually fill in the "localhost" part, and for that it is very difficult to work with mail.From = txtEmail.Text, because different people use different smtp hosts.
    There's nothing wrong with that if your SMTP server is on the same machine as the webserver.

    You can also allow any from address if the SMTP server is acting as a relay although admittedly this isn't usually desirable.

  7. #7
    Junior Member
    Join Date
    Nov 2008
    Posts
    20

    Re: Send email with textbox values

    hmmm, i didn't know that, sorry, didn't mean to give anybody wrong advice!

    I just spent hours and hours trying to get the simple email script to work a couple of days ago, and I found that using a dummy adress is simply the easiest way to do so.

    But if people from other locations with different ISP's (and different SMTP server) send an email with this contact page, don't they need to use their smtp info? I can be very wrong here..

  8. #8
    Frenzied Member Fishcake's Avatar
    Join Date
    Feb 2001
    Location
    Derby, UK
    Posts
    1,092

    Re: Send email with textbox values

    If a webserver is setup as an open relay it will send the email so it appears as though it came from the user specified even if it isn't from a known user.

    This obviously is heaven for spammers though and the email may well be rejected by receiving mail servers as it will fail reverse DNS checks.

    I'm certainly not recommending this setup and using gmail is a perfectly good solution.

    EDIT: wikipedia link

  9. #9
    Frenzied Member Fishcake's Avatar
    Join Date
    Feb 2001
    Location
    Derby, UK
    Posts
    1,092

    Re: Send email with textbox values

    However for a production website you'd most likely want emails to come from an address at the same domain as your website which is why you'd have your own SMTP server.

  10. #10
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Send email with textbox values

    Your contact page will sit on your web server. This may be a company web server or a web host, presumably. You should, therefore have an SMTP server available to you already.

    Perhaps you don't have one, but on a serious website, I wouldn't use a third party... it's just unprofessional.

  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2008
    Posts
    268

    Re: Send email with textbox values

    Quote Originally Posted by mendhak
    Your contact page will sit on your web server. This may be a company web server or a web host, presumably. You should, therefore have an SMTP server available to you already.

    Perhaps you don't have one, but on a serious website, I wouldn't use a third party... it's just unprofessional.
    Hi guys thanks for your reply....

    And my error is...

    Http Exception was unhandled by user code.....

    in the line of SmtpMail.Send(mail);....

    and tel me where and how to configure the SMTP server....

    Thanks to all...
    Attached Images Attached Images   

  12. #12
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Send email with textbox values

    You've set your SMTPServer as localhost. You haven't answered FC's/Arsenal's questions about your SMTP Server so I'm assuming you don't have one. If you're trying to use the GMail servers to send your emails you'll need to authenticate yourself first:

    http://www.aspcode.net/Send-mail-fro...l-account.aspx

    If that's not what you want, you'll need to explain it to us again.

  13. #13

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2008
    Posts
    268

    Re: Send email with textbox values

    Quote Originally Posted by mendhak
    You've set your SMTPServer as localhost. You haven't answered FC's/Arsenal's questions about your SMTP Server so I'm assuming you don't have one. If you're trying to use the GMail servers to send your emails you'll need to authenticate yourself first:

    http://www.aspcode.net/Send-mail-fro...l-account.aspx

    If that's not what you want, you'll need to explain it to us again.
    Hi Mendhak...

    Thanks for your reply...
    Ya i dont have a SMTP server....

    But i like to test my application without a SMTP server as my own...


    How to use it tel me....

  14. #14
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Send email with textbox values


  15. #15

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2008
    Posts
    268

    Re: Send email with textbox values

    Hi Mendhak

    I installed the IIS and configured the IIS.. but still i'm having the same error....

    How to add the site to the IIS server and how to run it...

    Thanks in advance....

  16. #16
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Send email with textbox values

    In project properties, click on the web tab. In there, you should have an option that lets you specify the name of the virtual directory to use. There is a button there too that lets you create and configure the virtual directory in IIS, just to make things easier.

Posting Permissions

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



Click Here to Expand Forum to Full Width