We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,254 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

How to send automatic Email in C#

I am creating a website where i want to send email notification of every website activity like Facebook
How can i send automatic emails to logged in user?

Thank You.

3
Contributors
2
Replies
1 Day
Discussion Span
10 Months Ago
Last Updated
3
Views
Jigs28
Light Poster
48 posts since Jan 2012
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

To send an email is fairly easy. First you need to import the System.Net.Mail namespace to get access to everything you need. Then you create an instance of an SmtpClient (which you provide with the details regarding the email account that will be sending the email) and a MailMessage instance which holds the subject, message, attachments, etc. Then send it.
You'll find plenty of good tutorials online. Here is one to start you off:
http://www.dreamincode.net/forums/topic/57355-sending-e-mail-messages-using-c%23/

hericles
Veteran Poster
1,065 posts since Nov 2007
Reputation Points: 156
Solved Threads: 228
Skill Endorsements: 9

You need to have a service (or an application) running on the server (or which is run on the server as regular intervals) which monitors your data source, and sends the emails.
This code was developed in VB.Net code, you have to convert the code.

        Dim mailMsg As MailMessage = New MailMessage
        Dim smtpClient As SmtpClient = New SmtpClient

        mailMsg.To.Add("xyz@gmail.com")
        mailMsg.Subject = "Silverlight Project Executed"
        mailMsg.Body = "Config Mail"
        mailMsg.Attachments.Add(New Attachment("AttachedFileName"))

        mailMsg.IsBodyHtml = True
        mailMsg.From = New MailAddress("abc@gmail.com")

        smtpClient.Credentials = New NetworkCredential("abc@gmail.com", "pass1234")
        smtpClient.Host = "smtp.gmail.com"
        smtpClient.Port = 25
        smtpClient.EnableSsl = True

        smtpClient.Send(mailMsg)

Source: forums.silverlight.net/t/162682.aspx/1

GarryHillton
Light Poster
48 posts since Jul 2011
Reputation Points: 5
Solved Threads: 1
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0717 seconds using 2.66MB