locked
Help with receiving eMails RRS feed

  • Question

  • User-371148474 posted

    Hi,

    I know the webmail helper helps with sending mails from your application. What about receiving mails from a contact form, a feedback form..

    How do I go about that.... 

    Wednesday, July 30, 2014 10:17 AM

Answers

  • User895691971 posted

    If you want to say, that you want to get an Email when a user submits the contact form or some feedback about some data on your website. Then you can use the WebMail helper as you want. Actually WebMail is just a helper that would send the email whenever you want it to do so. It is upto you, where and when you want it to send the email and what content must be added to it in order to get the actual content that user wants to send to you through that form. 

    I would go with only the Contact form and I would give you a details about how you can do this job and get the Email when user sends some information to you. You can use this data and make up a Feedback service in your ASP.NET Web App.

    First of all, you create a form to allow the user to add in the details about himself or the message that he wants to send to you.

    <form method="post">
       <label for="name">Name</label>
       <input type="text" name="name" id="name" />
       <label for="email">Email</label>
       <input type="email" name="email" id="email" />
       <label for="message">Message</label>
       <textarea name="message" id="message"></textarea>
    </form>

    That was the code required to create a simple Contact form that would do the work. Now, the real thing comes in the Server-side code when this block is executed (form is submitted). That code would be like this

    @{
     ...
       if(IsPost) {
         // initialization
         var name = Request.Form["name"];
         var email = Request.Form["email"];
         var message = Request.Form["message"];
    
         // WebMail settings
         // you donot need to do these, if already done in _AppStart.cshtml
         WebMail.UserName = "your-user-name";
         WebMail.From = "shown-in-email";
         WebMail.Password = "password";
         WebMail.SmtpServer = "your-user-name"; // smtp.gmail.com for gmail
         WebMail.SmtpPort = 25; // well, works with most
         WebMail.EnableSsl = true; // required for most of the servers
    
         // send email with the details. '@' is used to create multiline strings in ASP.NET
         WebMail.Send(to: "your-email-address",
                      subject: name + " contacted",
                      body: name + "has contacted the service. His email account is: " + email + 
                            ".He sent the following message: \n" + message
                     );
       }
     ...
    }

    This would now, send the email to your email account with the Subject of the [username] Contacted, and the body would include his name, email and the message. 

    Actually this is not an ideal case to send the email because it includes the data, but no other information. You can add more and more data to the body to make the Email beautiful. You can get the idea, that you want send the Email whereever you want from. You can include as much detail as you want to be added. This way, at any instance of your App, you can send the information back to your inbox with the required details and it won't take time writing the code either, thanks to ASP.NET.

    Good luck! :-)

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, July 30, 2014 2:29 PM

All replies

  • User379720387 posted

    Those aren't really emails.  They are forms, contact form and feedback form.

    You would need a third party provider to receive email, if you want to integrate with your application.

    Wednesday, July 30, 2014 10:31 AM
  • User895691971 posted

    If you want to say, that you want to get an Email when a user submits the contact form or some feedback about some data on your website. Then you can use the WebMail helper as you want. Actually WebMail is just a helper that would send the email whenever you want it to do so. It is upto you, where and when you want it to send the email and what content must be added to it in order to get the actual content that user wants to send to you through that form. 

    I would go with only the Contact form and I would give you a details about how you can do this job and get the Email when user sends some information to you. You can use this data and make up a Feedback service in your ASP.NET Web App.

    First of all, you create a form to allow the user to add in the details about himself or the message that he wants to send to you.

    <form method="post">
       <label for="name">Name</label>
       <input type="text" name="name" id="name" />
       <label for="email">Email</label>
       <input type="email" name="email" id="email" />
       <label for="message">Message</label>
       <textarea name="message" id="message"></textarea>
    </form>

    That was the code required to create a simple Contact form that would do the work. Now, the real thing comes in the Server-side code when this block is executed (form is submitted). That code would be like this

    @{
     ...
       if(IsPost) {
         // initialization
         var name = Request.Form["name"];
         var email = Request.Form["email"];
         var message = Request.Form["message"];
    
         // WebMail settings
         // you donot need to do these, if already done in _AppStart.cshtml
         WebMail.UserName = "your-user-name";
         WebMail.From = "shown-in-email";
         WebMail.Password = "password";
         WebMail.SmtpServer = "your-user-name"; // smtp.gmail.com for gmail
         WebMail.SmtpPort = 25; // well, works with most
         WebMail.EnableSsl = true; // required for most of the servers
    
         // send email with the details. '@' is used to create multiline strings in ASP.NET
         WebMail.Send(to: "your-email-address",
                      subject: name + " contacted",
                      body: name + "has contacted the service. His email account is: " + email + 
                            ".He sent the following message: \n" + message
                     );
       }
     ...
    }

    This would now, send the email to your email account with the Subject of the [username] Contacted, and the body would include his name, email and the message. 

    Actually this is not an ideal case to send the email because it includes the data, but no other information. You can add more and more data to the body to make the Email beautiful. You can get the idea, that you want send the Email whereever you want from. You can include as much detail as you want to be added. This way, at any instance of your App, you can send the information back to your inbox with the required details and it won't take time writing the code either, thanks to ASP.NET.

    Good luck! :-)

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, July 30, 2014 2:29 PM
  • User-371148474 posted

    I would like the sender's email address be included as from

    Not my email address repeating itself in the from label and to label

    Wednesday, July 30, 2014 3:12 PM
  • User895691971 posted

    You can simply edit the code I provided you with then. I already told you, you can change the code to make it a fit for your needs. I have not provided the perfect or ideal code, I have tried to teach you how to write the code to get the email when user contacts you or sends a feedback. That was my intent.

    Wednesday, July 30, 2014 4:44 PM