Click here to Skip to main content
15,893,486 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi,
I want know, how to send a mail automatically to other using webservice in asp.net4.0

could u help with coding ...

Thanks,
Posted
Updated 9-Jan-12 20:36pm
v3
Comments
Sergey Alexandrovich Kryukov 10-Jan-12 1:36am    
Help with what? What does this "automatically" mean? On what events, where, what's the content. Why, after all?
--SA

look man on a special event you have to to use this code:

C#
try
        {
            MailMessage mM = new MailMessage();
            mM.From = new MailAddress("final_project_youssef@hotmail.com");
            mM.To.Add("final_project_youssef@hotmail.com");
            mM.Subject = "your subject line will go here";
            //mM.Attachments.Add(new Attachment(@"C:\\attachedfile.jpg"));
            mM.Body = reContactUs.Text;
            mM.IsBodyHtml = true;
            SmtpClient sC = new SmtpClient("smtp.live.com");//this is the smtp of hotmail
            //port number for Hot mail
            sC.Port = 25;
            sC.Credentials = new NetworkCredential("your Email@hotmail.com", "password");
            sC.EnableSsl = true;
            sC.Send(mM);
        }
        catch (Exception ex)
        {
            throw ex;
        }
 
Share this answer
 
System.Net.Mail namespace in .NET framework helps to send email from asp.net. MSDN reference at:http://msdn.microsoft.com/en-us/library/dk1fb84h.aspx[^]

Sample code is:
C#
private static void SendEmail(MailAddress fromAddress, MailAddress toAddress, string subject, string body)
{
    var message = new MailMessage(fromAddress, toAddress)
                      {
                          Subject = subject,
                          Body = body
                      };

    var client = new SmtpClient("smtpServerName");
    client.Send(message);
}
 
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