Click here to Skip to main content
15,868,292 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hai everybody. i am new for creating mailserver. so i need a help from you. i create one form. after filling all the detaills, i nedd to send mail to the customer.


my code is like this:
C#
MailMessage mail = new MailMessage();
        mail.To.Add(Txt_Email.Text);
        mail.From = new MailAddress("myemailid");
        mail.Subject = "Sending an email";
        mail.Body = "Date ";
        SmtpClient smtp = new SmtpClient("mail.gmail.com");
        //TODO: Add SMTP Authentication
        //smtp.Credentials = new NetworkCredentials("user", "password");
        smtp.Send(mail);


but i raise an error. plz any solve my problem
Posted
Updated 17-Dec-11 1:09am
v2

try this method
C#
public static Boolean SendingMail(string From, string To, string Subject, string Body)
   {

           try
           {
               MailMessage m = new MailMessage("<id@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("id@gmail.com", "pass@1234");
               smtp.UseDefaultCredentials = false;
               smtp.Credentials = authinfo;
               smtp.Send(m);
               return true;




           }
           catch (Exception ex)
           {
               return false;
           }
       }
 
Share this answer
 
Comments
resonance_siv 17-Dec-11 7:14am    
me 5
krantikumar panda 17-Dec-11 7:29am    
thank for give answer to me. but it still raise an exception as failure sending mail.
hope this ll give some idea
u ve to give the mailid of urs and password either in webconfig file or in the same page.

C#
using System.Net.Mail;
add this
smtp.Credentials = new System.Net.NetworkCredential
       ("YourUserName@gmail.com","YourGmailPassword");
 smtp.EnableSsl = true;
  smtp.Send(mail);


if problem still persist 
add 
smpt.port=587;
 
Share this answer
 
v4
Comments
krantikumar panda 17-Dec-11 7:30am    
thank for give answer to me. but it still raise an exception as failure sending mail.
 
Share this answer
 
Comments
krantikumar panda 17-Dec-11 7:56am    
thanks for given reply and send solutions to me. now my problem is solved
Hi,

Gmail use SSL (Secured socket layer) for sending email. so you required to enable SSL for SmtpClient.


it will be always better if you can post exact your error message.

hope it will resolve your problem.

thanks
-amit
 
Share this answer
 
VB
Dim message As New MailMessage()
message.From = New MailAddress("my@gmail.com", "SendersNametoAppear")

message.To.Add("UrEmail@yah.com")

'message.CC.Add(New MailAddress("recpt@yahoo.com"))
message.Subject = "New Message!"
message.SubjectEncoding = System.Text.UTF8Encoding.UTF8
message.Body = RemoveHTML(elm1.Value.ToString)
message.BodyEncoding = System.Text.UTF8Encoding.UTF8
'message.Priority = MailPriority.High

Dim client As New SmtpClient("smtp.gmail.com")
Dim credentials As New System.Net.NetworkCredential("my@gmail.com", "urpassword")
client.Credentials = credentials
client.EnableSsl = True
client.Send(message)



Hi Bro! you can try this code, hope it helps..
 
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