Skip to content Skip to sidebar Skip to footer

Trying To Send A Basic Email To Folder

I am trying to send a basic email to a folderbut howerver, even though I do receive the email, the body is missing completely. private void MailReport() { string to = 'arianul

Solution 1:

You can try something like below.

protected void SendMail()
{
    // Gmail Address from where you send the mail
    var fromAddress = "Gmail@gmail.com";
    // any address where the email will be sending
    var toAddress = YourEmail.Text.ToString(); 
    //Password of your gmail address
    const string fromPassword = "Password";
     // Passing the values and make a email formate to display
    string subject = YourSubject.Text.ToString();
    string body = "From: " + YourName.Text + "\n";
    body += "Email: " + YourEmail.Text + "\n";
    body += "Subject: " + YourSubject.Text + "\n";
    body += "Question: \n" + Comments.Text + "\n";
    // smtp settings
    var smtp = new System.Net.Mail.SmtpClient();
    {
        smtp.Host = "smtp.gmail.com";
        smtp.Port = 587;
        smtp.EnableSsl = true;
        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);
}

protected void Button1_Click(object sender, EventArgs e)
{
    try
    {
        //here on button click what will done 
        SendMail();
        DisplayMessage.Text = "Your Comments after sending the mail";
        DisplayMessage.Visible = true;
        YourSubject.Text = "";
        YourEmail.Text = "";
        YourName.Text = "";
        Comments.Text = "";
    }
    catch (Exception) { }
}

For more information check Send Mail / Contact Form using ASP.NET and C#

I hope this will help to you.


Solution 2:

it seems that you are missing the:

MailMessage msg = new MailMessage(from, to);
msg.Subject = subject;

msg.Body = body; <--- try adding this and see what happens.

msg.Body property is empty in your example, I guess that's why it doesn't send the body text.


Post a Comment for "Trying To Send A Basic Email To Folder"