Click here to Skip to main content
15,905,504 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I write a sharepoint web part for sending mail

I use same code for windows form application windows form application sending mail but sharepoint web part gives me a error

Below this error
Server Error in '/' Application.
The remote name could not be resolved: 'smtp host name'

code below
C#
MailAddress ma = new MailAddress("mailadresss", "Admin");

           MailMessage posta = new MailMessage();
           posta.Body = TextBox2.Text;
           posta.Subject = TextBox1.Text;
           posta.To.Add(Label2.Text);
           posta.From = ma;
           posta.Priority = System.Net.Mail.MailPriority.High;

           SmtpClient smtp = new SmtpClient();
           smtp.Credentials = new System.Net.NetworkCredential("mailadress", "password");
           smtp.Port = 25;
           smtp.Host = "smtp host name";
           smtp.Send(posta);


I don't understand same code but givess error
Posted
Updated 28-Dec-11 0:48am
v3
Comments
Wendelius 28-Dec-11 6:48am    
Pre tags added

There could be a couple of things happening here. The first thing I would suggest is to use exception handling to find the actual error. Or look at the ULS logs to trace the problem. Make sure the communication between the servers is not being disrupted. If all else, SharePoint has its own mechanism for sending email, SPUtility.SendEmail[^]
 
Share this answer
 
You need to change 'smtp host name' to a valid SMTP host name (SMTP server).

Good luck!
 
Share this answer
 
Comments
Member-2338430 28-Dec-11 7:59am    
valid my smtp host name can be different error what do you think about?
Member-2338430 28-Dec-11 8:00am    
if smtp host name is not valid how ı send a mail with windows form application?
[no name] 28-Dec-11 8:46am    
You don't get that the OP doesn't want to give the actual SMTP server name and has just put a placeholder in?
E.F. Nijboer 29-Dec-11 8:02am    
But that doesn't really change anything about the answer. Both 'smtp host name' or the actual undisclosed name of the SMTP server give the same error 'The remote name could not be resolved' which would indicate that the SMTP server or related property like Port isn't correct.

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