Sending mail

  • Thread starter Thread starter perspolis
  • Start date Start date
P

perspolis

Hi
I'm using System.Net.Mail to send a mail.
It dosen't work properly.it sends but I can't get it in the destination.but
with previous namespace System.Web.Mail I can send mail successfully.
I set all of properties like each other..
I don't know what the problem is ?

thanks in advance
 
Thabks but I do the same way you did but it dosen't work.
but it works with System.Web.Mail
 
here is an example of a very simple mail sending class. You may wish to check
this code against the code that you are using:


using System.Net.Mail;
namespace PAB.Utils
{
public class MailUtil
{
private MailUtil() { }
public static void SendMail(string smtpServer, string fromAddress, string
toAddress, string subject, string body)
{
System.Net.Mail.SmtpClient test = new System.Net.Mail.SmtpClient();
test.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
test.UseDefaultCredentials = true;
test.Host = smtpServer;
test.Send(fromAddress,toAddress,subject,body);
}
}
}

--Peter
 
Another approach:

MailMessage message = new MailMessage(
"(e-mail address removed)",
"(e-mail address removed)",
"subject text",
"body text");
SmtpClient client = new SmtpClient("server name");
client.Credentials = CredentialCache.DefaultNetworkCredentials;
client.Send(message);

Above code taken from the following link:
The System.Net.Mail Namespace:
http://msdn2.microsoft.com/en-us/library/system.net.mail(VS.80).aspx

A tutorial for System.Net.Mail:
http://compsci.chester.ac.uk/dotNETTutorial/Lesson2.aspx
 
Back
Top