Hi sir,
I am uploading one excel file which have two cols one is for Full Name & the other is Email. Now i want send email to those who are in Excel sheet Emails. Then what should be my Send_Mail Action in Controller . Please Help.
This is my Email_Load Action Post code in controller. and which excel file uploading successfully.
[HttpPost, ActionName("Email_Load")]
public ActionResult Email_Load_confirmed(HttpPostedFileBase file)
{
File_Model tz = new File_Model();
try
{
if (file != null)
{
file.SaveAs(Server.MapPath("~/App_Data/Uploads/Contacts.xlsx" + ".xlsx"));
ViewBag.Message = "file is uploaded successfully!";
_Stores Stores_ = new _Stores();
Basic_Helper _Basic_Helper = new Basic_Helper();
var Store = Stores_.Get_Store_Info_Prd(_Basic_Helper.Format_URL(Request.Url.Host.ToString()));
if (Store != null)
{
_Basic_Helper = null;
_Site_Info Site_Info = new _Site_Info();
string connectionString = "Provider=Microsoft.Jet.OleDb.4.0;Data Source=" + Server.MapPath("~/App_Data/Uploads/Contacts.xlsx") + ";";
connectionString += "Extended Properties=Excel 8.0;";
OleDbCommand myCommand = new OleDbCommand("Select * from [Sheet1$];");
OleDbConnection myConnection = new OleDbConnection(connectionString);
myConnection.Open();
myCommand.Connection = myConnection;
OleDbDataReader myReader = myCommand.ExecuteReader();
while (myReader.Read())
{
if (!myReader.GetValue(1).ToString().Equals(""))
{
Site_Info.Insert_Cust_Det_Newsletter(Store.ID, myReader.GetValue(0).ToString(), myReader.GetValue(1).ToString());
}
}
myReader.Close();
myCommand.Cancel();
myConnection.Close();
myConnection = null;
Site_Info = null;
}
Store = null;
Stores_ = null;
System.IO.File.Delete(Server.MapPath("~/App_Data/Uploads/Contacts.xlsx"));
}
}
catch (Exception ex)
{
string t = ex.ToString();
t = "";
}
return View();
}
And this is my View Code For Send_Mail
<form method="POST" action="/cgi-bin/email">
<table>
<tr>
<td>From:*</td>
<td>
<input name="sender" value="admin@tradercart.com" placeholder="admin@tradercart.com" required></td>
</tr>
<tr>
<td>Subject:*</td>
<td>
<input name="sender" placeholder="Subject" required></td>
</tr>
<tr>
<td>Please type a message:</td>
<td>
<textarea name="content_message" rows="5" cols="60" placeholder="Here's some text."></textarea></td>
</tr>
<tr>
<td></td>
<td>
<input type="submit" value="Send">
<input type="reset" value="reset"></td>
</tr>
</table>
</form>
Kindly Tell me what should be Send_Mail Action In controller?????
public ActionResult Send_Mails()
{
??
}
Please help me its will be highly appreciated
Thanks
Regards,
Tahir