2011-04-18 18 views
7

2003 ve visual studio 2008'i kullanıyorum. E-postayı herhangi bir alana gönderecek bir uygulama geliştirmek istiyorum. ama gmail, hotmail vb. e-posta göndermeye çalışırken kodum başarısız oluyor, aslında tüm mesajlar C:\Inetpub\mailroot\Queue dizininde saklanıyor. Lütfen e-postayı gmail'e, hotmail a/c'ye nasıl gönderdiğimi bildirin. PeşinSMTPclient C# kullanarak gmail e-posta göndermek nasıl?

Teşekkür

Kod

System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(); 
message.To.Add("[email protected]"); 
message.To.Add("[email protected]");    
message.Subject = "This is sample mail"; 
message.From = new System.Net.Mail.MailAddress("[email protected]"); 
message.Body = "this is the message body"; 


System.Net.Mail.SmtpClient sss = new System.Net.Mail.SmtpClient("HO-KKJ-MAIL.in.niit.com"); 
sss.UseDefaultCredentials = false; 
sss.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis; 
sss.Credentials = new System.Net.NetworkCredential("Sumit.Dhingrar", "password","domain"); 
+1

Kimlik bilgileriniz doğru mu? Herhangi bir hata mesajı alıyor musunuz? – Mizipzor

+0

Deneme sss.EnableSsl = true; ' – KaeL

cevap

11

Bu

string from = [email protected]; //Replace this with your own correct Gmail Address 

string to = [email protected] //Replace this with the Email Address to whom you want to send the mail 

System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage(); 
mail.To.Add(to); 
mail.From = new MailAddress(from, "One Ghost" , System.Text.Encoding.UTF8); 
mail.Subject = "This is a test mail" ; 
mail.SubjectEncoding = System.Text.Encoding.UTF8; 
mail.Body = "This is Email Body Text"; 
mail.BodyEncoding = System.Text.Encoding.UTF8; 
mail.IsBodyHtml = true ; 
mail.Priority = MailPriority.High; 

SmtpClient client = new SmtpClient(); 
//Add the Creddentials- use your own email id and password 

client.Credentials = new System.Net.NetworkCredential(from, "Password"); 

client.Port = 587; // Gmail works on this port 
client.Host = "smtp.gmail.com"; 
client.EnableSsl = true; //Gmail works on Server Secured Layer 
     try 
     { 
      client.Send(mail); 
     } 
     catch (Exception ex) 
     { 
      Exception ex2 = ex; 
      string errorMessage = string.Empty; 
      while (ex2 != null) 
      { 
       errorMessage += ex2.ToString(); 
       ex2 = ex2.InnerException; 
      } 
    HttpContext.Current.Response.Write(errorMessage); 
     } // end try 

C# yılında Gmail ile e-posta gönderme için iyi bir örnektir Emin misiniz olduğunu

message.From = new System.Net.Mail.MailAddress("[email protected]"); 

haklı mı? Bu yöntemin böyle bir aşırı yükü var mı?

İlgili konular