Click here to Skip to main content
15,891,864 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all


i want to sent email from my website , to notify the person that he has logged to the website.


i tried following code:

C#
string from_m = "mailto@gmail.com", sub = "success", mbody = "mail body";
        MailMessage mailObj = new MailMessage(from_m ,txbemail.Text,sub,mbody);
        SmtpClient SMTPserver = new SmtpClient("localhost");
        try
        {
            SMTPserver.Send(mailObj);
        }
        catch(Exception ex)
        {
            Label7.Text = ex.ToString();
        }
        txbemail.Text = "";
        txbpwd.Text = "";
        if (flag == 1)
        {
            //Session["Ufname"] = txbemail.Text;
            btsignin.PostBackUrl = "staff_profile.aspx";
        }
        else
        {
            Label6.Text = "Invalid User,<br />Check Your Email Id and Password.";
            //Response.Write("Not an authorised user.");
        }


and iam getting the following error...

System.Net.Mail.SmtpException: Failure sending mail. ---> System.IO.IOException: Unable to read data from the transport connection: net_io_connectionclosed. at System.Net.Mail.SmtpReplyReaderFactory.ProcessRead(Byte[] buffer, Int32 offset, Int32 read, Boolean readLine) at System.Net.Mail.SmtpReplyReaderFactory.ReadLines(SmtpReplyReader caller, Boolean oneLine) at System.Net.Mail.SmtpReplyReaderFactory.ReadLine(SmtpReplyReader caller) at System.Net.Mail.SmtpReplyReader.ReadLine() at System.Net.Mail.SmtpConnection.GetConnection(String host, Int32 port) at System.Net.Mail.SmtpTransport.GetConnection(String host, Int32 port) at System.Net.Mail.SmtpClient.GetConnection() at System.Net.Mail.SmtpClient.Send(MailMessage message) --- End of inner exception stack trace --- at System.Net.Mail.SmtpClient.Send(MailMessage message) at home_page.btsignin_Click(Object sender, EventArgs e) in e:\kfri_auto\automate\home_page.aspx.cs:line 11



iam using visual studio 2008
iis 5.1


can any one help me
plzz
i googled a lot..but not clear
plz help

will be great

thanks in advance
Posted
Updated 23-Nov-11 18:54pm
v3

 
Share this answer
 
Comments
Ragi Gopi 24-Nov-11 1:06am    
then the error is:


System.Net.Mail.SmtpException: Failure sending mail. ---> System.Net.WebException: The remote name could not be resolved: 'smtp.gmail.com' at System.Net.ServicePoint.GetConnection(PooledStream PooledStream, Object owner, Boolean async, IPAddress& address, Socket& abortSocket, Socket& abortSocket6, Int32 timeout) at System.Net.PooledStream.Activate(Object owningObject, Boolean async, Int32 timeout, GeneralAsyncDelegate asyncCallback) at System.Net.PooledStream.Activate(Object owningObject, GeneralAsyncDelegate asyncCallback) at System.Net.ConnectionPool.GetConnection(Object owningObject, GeneralAsyncDelegate asyncCallback, Int32 creationTimeout) at System.Net.Mail.SmtpConnection.GetConnection(String host, Int32 port) at System.Net.Mail.SmtpTransport.GetConnection(String host, Int32 port) at System.Net.Mail.SmtpClient.GetConnection() at System.Net.Mail.SmtpClient.Send(MailMessage message) --- End of inner exception stack trace --- at System.Net.Mail.SmtpClient.Send(MailMessage message) at home_page.btsignin_Click(Object sender, EventArgs e) in e:\kfri_auto\automate\home_page.aspx.cs:line 146
uspatel 24-Nov-11 2:02am    
public static Boolean SendingMail(string From, string To, string Subject, string Body)
{

try
{
MailMessage m = new MailMessage("Test<sender@gmail.com>", To);
m.Subject = Subject;
m.Body = Body;
m.IsBodyHtml = true;
m.From = new MailAddress(From);

m.To.Add(new MailAddress(To));
SmtpClient smtp = new SmtpClient();
smtp.Host = "mail.google.com";

NetworkCredential authinfo = new NetworkCredential("test@gmail.com", "te1234");
smtp.UseDefaultCredentials = false;
smtp.Credentials = authinfo;
smtp.Send(m);
return true;




}
catch (Exception ex)
{
return false;
}
}
try this method
 
Share this answer
 
Comments
Ragi Gopi 24-Nov-11 2:23am    
thanks for your help..and for considering me...

sorry again the same error occurs.
Hi,
you have to check two things

1. toaddress that you have mentioned whether it's correct or not.
2. You should give the correct SMPT cleint instead of localhost
 
Share this answer
 
Hi Uma,
Sending Email[^]
 
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