Click here to Skip to main content
11,480,082 members (67,851 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET4.0
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 9-Jan-12 20:34pm
Edited 9-Jan-12 21:36pm
v3
Comments
SAKryukov at 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
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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

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;
        }
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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:
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);
}
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 235
1 Sergey Alexandrovich Kryukov 215
2 Richard MacCutchan 100
3 F-ES Sitecore 75
4 DamithSL 65
0 Sergey Alexandrovich Kryukov 7,890
1 OriginalGriff 7,556
2 Sascha Lefèvre 3,064
3 Maciej Los 2,491
4 Richard Deeming 2,335


Advertise | Privacy | Mobile
Web01 | 2.8.150520.1 | Last Updated 10 Jan 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100