Click here to Skip to main content
15,914,111 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
here this code is to send mail body is :
""""""""""""""""""""""""""""""""""""""""""""""""""""""
ERROR IS FAILURE SENDING MAIL.......
""""""""""""""""""""""""""""""""""""""""""""""""
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Globalization;
using System.Net;
using System.IO;
using System.Xml.Linq;
using System.Net.Mail;


public partial class emergency : System.Web.UI.Page
{
    string gMailAccount = "xxxxxxx@gmail.com";
    string password = "xxxxxxx";
    string to;
    string subject = "Welcome to scalabe and secure personal health records.";
    string message;
    SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["phr"]);
    string sta = "read",keey="null";
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        con.Open();
        SqlCommand cmd = new SqlCommand("insert into emergency values('" + TextBox1.Text + "','" + TextBox2.Text + "','" + TextBox3.Text + "','"+sta+"','"+keey+"')", con);
        cmd.ExecuteNonQuery();
        if(TextBox1.Text!=null&&TextBox2.Text!=null&&TextBox3.Text!=null)
        {
            System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
            message.To.Add(gMailAccount);
            message.Subject = "This is the Subject line";
            message.From = new System.Net.Mail.MailAddress("yyyyyyyyyyyy@gmail.com");
            message.Body = "This is the message body";
            System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("yoursmtphost");
            smtp.Send(message);
              MsgBox.Show("secret key send to ur mail id");
        }
        con.Close();

    }
}
Posted
Updated 23-Feb-14 9:12am
v3
Comments
Pranav-BiTwiser 23-Feb-14 12:26pm    
I have worked on this project before.....PHR
from where have u got this project

Refer my previous answer sending email to gmail from asp.net[^].

You will get the full working code.

Note - Please don't post the mail id and password in your question. Delete those, otherwise you might get spam mails.
 
Share this answer
 
 
Share this answer
 
Comments
gankidi bhrath 23-Feb-14 2:47am    
i modified my code and the error occured is

"The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Must issue a STARTTLS command first. qq5sm37789380pbb.24 - gsmtp"




MailMessage message = new MailMessage();
message.To.Add(to);
message.Subject = "This is the Subject line";
message.From = new MailAddress("iamromantic143@gmail.com");
message.Body = "This is the message body";
SmtpClient smtp = new SmtpClient();
smtp.Port = 25;
smtp.Host = "smtp.gmail.com";
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.UseDefaultCredentials = false;
smtp.Send(message);
MsgBox.Show("secret key send to ur mail id");
Peter Leow 23-Feb-14 3:41am    
So you use gmail as smtp server, read this: http://www.codeproject.com/Questions/254743/sending-email-in-asp-net-using-smtp-gmail-server
gankidi bhrath 23-Feb-14 9:19am    
tanq
 
Share this answer
 
The code seems to be OK.
I think that you can not post emails from localhost if you don't have smtp server or some mail server on localhost. I had the same problem in php. For php exists a mailserver exe file, that provides the function of sending mails from localhost.

Try to find: how to send mail from localhost in asp.NET
http://stackoverflow.com/questions/18803600/how-to-send-mail-using-localhost-and-from-asp-net-website-i-cant-get-the-smtp-t[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900