Click here to Skip to main content
15,884,986 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
try
       {
           string name = txt_name.Text;
           string email = txt_email.Text;
           string subject = txt_subject.Text;
           string msg = txt_area.Text;

           MailMessage m = new MailMessage();
           SmtpClient sc = new SmtpClient();
           m.From = new MailAddress("vehicletrack2013@gmail.com", "Vehicle Track");
           m.Sender = new MailAddress(email, name);
           m.To.Add(new MailAddress(destination email));
           m.To.Add(new MailAddress(destination email));

           m.Subject = subject;
           m.Body = msg;
           //similarly BCC m.Subject = "Test"; m.Body = "This is a Test Mail";
           sc.Host = "smtp.gmail.com";
           sc.Port = 587;
           sc.Credentials = new System.Net.NetworkCredential(email id from where email send, password;);

           sc.EnableSsl = true;
           sc.Send(m);
           txt_name.Text = "";
           txt_email.Text = "";
           txt_subject.Text = "";
           txt_area.Text = "";
           alert_div.Visible = true;
           alert_span.InnerHtml = "Message has been submitted";
       }
       catch (Exception ex)
       {
           alert_span.InnerHtml = "Could not send the e-mail";
       }



when i use this in .net than it work properly but when i upload my site than it cant work
please help me
Posted
Comments
JoCodes 2-Oct-13 7:30am    
IS it throwing some exception error messages? if so can you post that too?
Bama Boy 2-Oct-13 7:32am    
no sir i cant get any message
but when i run in .net than it work
but not work when i upload my site
JoCodes 2-Oct-13 7:39am    
Your host seems to be restricting your smtp access
Bama Boy 2-Oct-13 7:41am    
ohk

you cant set gmail account as source address bcoz when you upload this project onto server gmail server prevent you to send mail.

so instead of using gmail address just create one email id on your server then try.
hope it will work
 
Share this answer
 
Comments
Bama Boy 2-Oct-13 7:34am    
ok i will try
Please check the machine for services on which you deployed your code.
may be that dont have access too SMTP server

Or It seems some problem with SMTP . So firstly check for gmail smtp. if it works then later replace gmail smtp by yours.

SmtpClient tSmtpClient = new SmtpClient("smtp.gmail.com",587);

-SG
 
Share this answer
 
Comments
Bama Boy 2-Oct-13 7:37am    
ok sir i will try
Bama Boy 2-Oct-13 7:39am    
i already given that host name and port no.
[no name] 2-Oct-13 7:41am    
it means problem is with your machine network. The one on whihc you are uploaading dont have access to SMTP server
please have a look in this article. it works perfectly.
 
Share this answer
 
Comments
Bama Boy 2-Oct-13 7:53am    
yes

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