-3

The front end

<table>
    <tr>
    <td>
        <asp:TextBox ID="rec_email" runat="server" ReadOnly="True">mymail@gmail.com</asp:TextBox>
    </td></tr>
        <tr>
    <td>
        <asp:TextBox ID="vol_name" runat="server" placeholder="Your Name" 
            Font-Names="Letter Gothic Std"></asp:TextBox>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="Please enter your name" Display="Dynamic" ControlToValidate="vol_name" SetFocusOnError="True"></asp:RequiredFieldValidator>   
    </td>
    </tr>
    <tr>
    <td>
        <asp:TextBox ID="sen_email" runat="server" placeholder="Your Email" 
            Font-Names="Letter Gothic Std"></asp:TextBox>
    </td></tr>
     <tr>
    <td>
        <asp:TextBox ID="phone_num" runat="server" placeholder="Your Number" 
            Font-Names="Letter Gothic Std"></asp:TextBox>
    </td></tr>
    <tr>
    <td>
        <asp:TextBox ID="msg_text" runat="server" TextMode="MultiLine" CssClass="msg" placeholder="Message"
            Height="96px" Width="130%" Font-Names="Letter Gothic Std" Font-Size="15px"></asp:TextBox>
    </td></tr>
    <tr>
    <td>
        <asp:Button ID="btn_send" runat="server" Text="Send" CssClass="button1" 
            onclick="btn_send_Click" />
    </td>
    </tr>
    </table>
     <asp:Label ID="Label1" runat="server" Font-Bold="True" 
         Font-Names="Letter Gothic Std" ForeColor="#0099FF"></asp:Label>
 </td>
 </tr>
 </table>

So, how to receive the messages send by the user in mymail@gmail.com

PS:This is just a dummy project, so is it possible without hosting the website? Thank you :)

PPS: And yes if it is possible, if i am able to get the messages in my gmail account then is it necessary to store their data in the database through this form?

Skullcandy
  • 77
  • 1
  • 1
  • 4

1 Answers1

0

With the following code you will be able to send email to a specific user,if you want to Send it through Front End request, it will be slightly different but logic will be the same

 using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Net;
 using System.Web;
 using System.Web.UI;
 using System.Web.UI.WebControls;

 namespace SendEmail
 {

   public partial class SendEmail : System.Web.UI.Page
  {
    protected void Page_Load(object sender, EventArgs e)
    {
      SendMail();
    }

    protected void SendMail()
    {

    var fromAddress = "";
    var toAddress = "";
    //Password of your gmail address
    const string fromPassword = "";
    string subject = "";
    string body = "";

    // smtp settings
    var smtp = new System.Net.Mail.SmtpClient();
    {
        smtp.Host = "smtp.gmail.com"";
        smtp.Port = 587;
        smtp.EnableSsl = false;
        smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
        smtp.Credentials = new NetworkCredential(fromAddress, fromPassword);
        smtp.Timeout = 20000;
    }
    // Passing values to smtp object
    smtp.Send(fromAddress, toAddress, subject, body);
   }
  }  
 }
Naive
  • 345
  • 2
  • 6
  • 18