Subscribe to Subscribers

Forums » .NET » ASP.NET »

Automation of mail using .net


Posted Date: 24 Jun 2012      Posted By:: mukul prady     Member Level: Silver    Member Rank: 3568     Points: 2   Responses: 5



hi,
I want a utility to make. The utility would be running back ground. utility will fetch the data from database and mail it at particular time (Suppose at 11:00 AM.) the utility would be running in background at particular time each day.




Responses

#677160    Author: Gaurav Agrawal      Member Level: Gold      Member Rank: 176     Date: 24/Jun/2012   Rating: 2 out of 52 out of 5     Points: 0

Check this URL : http://www.intstrings.com/ramivemula/articles/sending-automated-emails-asynchronously-using-a-c-windows-service-in-conjunction-with-database-email-records-part-ii/

Thanks & Regards,
Gaurav Agrawal
http://www.planetofcoders.com/


 
#677172    Author: Anil Kumar Pandey      Member Level: Platinum      Member Rank: 1     Date: 25/Jun/2012   Rating: 2 out of 52 out of 5     Points: 4

You may create a web service and deploy it in the server, check the time in the thread if it is equal to specified time you can read the data from data base and can send the mail.

here is the sample code to send mail.


protected void btnSubmit_Click(object sender, EventArgs e)
{
try
{
MailAddress SendFrom = new MailAddress(txtFrom.Text);
MailAddress SendTo = new MailAddress(txtTo.Text);

MailMessage MyMessage = new MailMessage(SendFrom, SendTo);

MyMessage.Subject = txtSubject.Text;
MyMessage.Body = txtBody.Text;

Attachment attachFile = new Attachment(txtAttachmentPath.Text);
MyMessage.Attachments.Add(attachFile);

SmtpClient emailClient = new SmtpClient(txtSMTPServer.Text);
emailClient.Send(MyMessage);

litStatus.Text = "Message Sent";
}
catch (Exception ex)
{
litStatus.Text=ex.ToString();
}
}


Thanks & Regards
Anil Kumar Pandey
Microsoft MVP, DNS MVM


 
#677199    Author: Pawan Awasthi        Member Level: Diamond      Member Rank: 4     Date: 25/Jun/2012   Rating: 2 out of 52 out of 5     Points: 3

Hai Mukul,
There are various ways to do this:
1. Create scheduler on IIS and set the time so that every day the same code should execute.
2. Create windows service which will execute all the time and check for the specific time to execute the code of sending mails.
Hope it will be helpful to you.

Regards,
Pawan Awasthi(DNS MVM)
+91 8143683708 (pawansoftit@gmail.com)
Outstanding Contribution Award..NTT Data Inc





 
#677205    Author: Prachi Kulkarni        Member Level: Gold      Member Rank: 33     Date: 25/Jun/2012   Rating: 2 out of 52 out of 5     Points: 4

Hi,
Please check the following code

Imports System.Data.SqlClient
Imports System.Net.Mail
Imports System.NetPublic Class Form1
Public Shared ConnectionString As String = ""
Public conn As New SqlConnection
Public ServerName As String
Public database As String = ""
Public Shared sysdate As Date
Dim selcmd As SqlCommand
Dim da As SqlDataAdapter
Dim ds As New DataSet()
Dim dr As DataRow

Private Sub btnSendMails_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSendMails.Click
If conn.State = 1 Then conn.Close()
conn.ConnectionString = ("Server=yourservername;Database=yourdatabasename;Integrated Security=True;Asynchronous Processing=True;")
conn.Open()
'MsgBox("connected")
sysdate = System.DateTime.Now()
Dim dt As String = sysdate.Day
selcmd = New SqlCommand("select * from yourtablename where Day (yourcolumnname) like '" & dt & "'", conn)
da = New SqlDataAdapter()
da.SelectCommand = selcmd
da.Fill(ds, "yourtablename")
DataGridView1.DataSource = ds.Tables("yourtablename")
For Each dr In ds.Tables("yourtablename").Rows
Dim ToAddress As String = dr("EmpEmailAddress")
Dim FromAddress As String = "yourmailadress@gmail.com"
Dim Subject As String = "Put some message here"
Dim Body As String = "Put some message here"

Dim mail As System.Net.Mail.MailMessage = New System.Net.Mail.MailMessage()
mail.To.Add(ToAddress)
mail.From = New MailAddress(FromAddress)
mail.Subject = Subject
mail.Body = Body
mail.Priority = System.Net.Mail.MailPriority.High
Dim client As SmtpClient = New SmtpClient("yourhostname", "port")
client.Credentials = CredentialCache.DefaultNetworkCredentials
client.Send(mail)
Next
End Sub
End Class

I hope it will be useful for you.

Regards,
Prachi.


 
#677350    Author: Ravindran        Member Level: Diamond      Member Rank: 3     Date: 25/Jun/2012   Rating: 2 out of 52 out of 5     Points: 4

Create one winodws application in the form load event write like this


using System.Net;
using System.Net.Mail;

namespace WindowsFormsApplication3
{

public partial class Form1 : Form
{
SqlConnection sqlcon = new SqlConnection(@"Server=RAVI\SQLEXPRESS;database=test;uid=xxxx;pwd=yyyy;");
SqlCommand sqlcmd = new SqlCommand();
SqlDataAdapter da;
DataTable dt = new DataTable();

public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
sendMail("yourid@anydomain.com");
}
void sendMail(String tomailid)
{
try
{
MailMessage msg = new MailMessage("fromid@gmail.com", tomailid, "subjectofmail", "Mail_Body");
SmtpClient mailClient = new SmtpClient("smtp.gmail.com", 587);
NetworkCredential NetCrd = new NetworkCredential("fromid@gmail.com", "fromidpassword");
mailClient.UseDefaultCredentials = false;
mailClient.Credentials = NetCrd;
mailClient.EnableSsl = true;
mailClient.DeliveryMethod = SmtpDeliveryMethod.Network;
mailClient.Send(msg);
}
catch (Exception ex)
{
}
}
}
}


Build that application in bin directory .exe file automatically created

Now go to control panel choose sheduled task -> Add Schedule task choose that exe file and select which data that exe run after that remainder email send automatically

Regards
N.Ravindran
Your Hard work never fails


 
Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.



Next : Drag Drop Problem For Ajax Controls
Previous : Treeview instead of dropdown
Return to Discussion Forum
Post New Message
Category:

Related Messages

Active Members
TodayLast 7 Daysmore...

Awards & Gifts
Talk to Webmaster Tony John
Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India
2005 - 2013 All Rights Reserved.
.NET and other trademarks mentioned in this site belong to Microsoft and other respective trademark owners.
Articles, tutorials and all other content offered here is for educational purpose only.
We are not associated with Microsoft or its partners.