Hi,
Just wanted put this out there to all the brainiacs because i just cant seem to do this.
I have a datagrid with columns
Date, DateNow, DateDifference, Email
They are all populated and i was wondering if when date difference hits 7 days it could send an email to everyone that has a date difference of 7 days or more.
I know how to send a single email but not how to go through the whole datagrid and do it.
Outlook.Application oApp = new Outlook.Application();
Outlook.MailItem email = (Outlook.MailItem)(oApp.CreateItem(Outlook.OlItemType.olMailItem));
email.Recipients.Add(textBox1.Text); //*need this for datagridview
email.Subject = "Reminder - 7 days difference;
email.Body = "7 Days Difference";
((Outlook.MailItem)email).Send();
Thanks alot for your patience and time.
If you could offer a code example it would be most appreciated.
Regards
Anthony
Loading
Subhendu DePosted Dec 9, 2010, 12:48 PM
Thanks.....
Anthony ClarkePosted Dec 9, 2010, 2:11 PM
Thanks :)
Anthony
Anthony ClarkePosted Dec 9, 2010, 11:53 AM
I Have VS 2010 Professional
Yes please if you wouldnt mind. Thank you so much. I included my source so you could see the kind of project im building. Its just a standard winform App.
Again, thanks alot
Subhendu DePosted Dec 9, 2010, 11:41 AM
I have VS 2010 Ultimate and if I send it, would it open in your machine? Do you have VS 2010 Ultimate?
If yes, I will send the whole solution. For the above reason, I send you only aspx, aspx.cs and aspx.designer.cs
Now you tell me the way to help you.
Thanks.....
Anthony ClarkePosted Dec 9, 2010, 11:28 AM
Thanks again for your help and time showing me this. Im not used to asp and im only a beginner in c#, how do i implement it? Would you be able to send me the solution file as im not sure what to do with the files you sent for me. You ability is far beyond mine.
Thankyou for taking the time out to help me Subhendu.
Ill also include my source - not that you need.
Subhendu DePosted Dec 9, 2010, 11:09 AM
Following is the code behind
public partial class WebForm4 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
grid1.DataSource = CreateMockObjects();
grid1.DataBind();
}
}
// It is only for illustration purpose
private IList
{
List
_mockclasses.Add(new MockClass(new DateTime(2010, 12, 9),"[email protected]"));
_mockclasses.Add(new MockClass(new DateTime(2010, 12, 11), "[email protected]"));
_mockclasses.Add(new MockClass(new DateTime(2010, 12, 10), "[email protected]"));
_mockclasses.Add(new MockClass(new DateTime(2010, 12, 9), "[email protected]"));
_mockclasses.Add(new MockClass(new DateTime(2010, 10, 8), "[email protected]"));
_mockclasses.Add(new MockClass(new DateTime(2010, 12, 7), "[email protected]"));
_mockclasses.Add(new MockClass(new DateTime(2010, 12, 6), "[email protected]"));
_mockclasses.Add(new MockClass(new DateTime(2010, 11, 22), "[email protected]"));
_mockclasses.Add(new MockClass(new DateTime(2010, 12, 4), "[email protected]"));
_mockclasses.Add(new MockClass(new DateTime(2010, 12, 1), "[email protected]"));
return _mockclasses;
}
// This is where you traverse each dataitem in datagrid and check. If true, send the mail.
protected void grid1_ItemDataBound(object sender, DataGridItemEventArgs e)
{
if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
{
int iDateDifference = Convert.ToInt16(e.Item.Cells[2].Text);
if (iDateDifference >= 7)
{
sendMail(e.Item.Cells[3].Text);
}
}
}
private void sendMail(string pEmail)
{
// put your send mail code
Response.Write("Mail send for " + pEmail + "
");
}
}
// This Class is not required by you. It is only for illustration purpose
public class MockClass
{
public DateTime MockDate { get; set; }
public DateTime DateNow { get; set; }
public Double DateDifference { get; set; }
public string EMail { get; set; }
public MockClass(DateTime pDate,string pEmail)
{
MockDate = pDate;
DateNow = DateTime.Now;
DateDifference = ( DateNow - MockDate).Days;
EMail = pEmail;
}
}
I also attached the code for your reference. First implement this thing then I will show you how to call the sendmail method asynchronously.
Thanks