Hi sir,
I generate employee payslip, id based on pdf file(Em1004.pdf) in a folder.
get employee id from pdf file name(employee id is split em1004) to find database employee e-mail id attached automatically send mail. same time to all
Ex.
folder name - D:\Payslip
having 10 pdf file Em1001.pdf, emp1002.pdf, emp1003.pdf...etc
i, need employee id split only pdf name Em1001 it's empid.
ii, that employee id based on find database employee mail id, (Select Mailid from tbl_employee where empid='pdffilename')
iii. process: get mailid- [email protected] ,attached file- em1001.pdf, Send payslip every employee mail id each one pdf attached.
that is sir. please help me
Loading
Thirunavukkarsu jPosted Jan 2, 2015, 7:33 AM
Sanjay KumarPosted Dec 31, 2014, 4:21 AM
try this
foreach (GridViewRow gr in GridView1.Rows)
{
CheckBox chkrow = (CheckBox)gr.FindControl("CheckBox");
lbl = new Label();
lbl = (Label)gr.Cells[2].FindControl("lblid");
if (chkrow.Checked == true)
{
string query;
try
{
conn.Open();
query = "select * from tblEmpSalary where emp_id='" + lbl.Text + "' ";
sqlcmd = new SqlCommand(query, conn);
da = new SqlDataAdapter(sqlcmd);
dt.Clear();
da.Fill(dt);
SqlDataReader reader = sqlcmd.ExecuteReader();
while (reader.Read())
{
lblEmail.Text = reader["Emp_Emailid"].ToString();
}
string PDFFile = @"D:\Payslip\" + empID + ".pdf";
//write pdf file GeneratePDF (your code)
System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
message.From = new MailAddress("[email protected]");
if (lblEmail.Text != null)
{
message.To.Add(lblEmail.Text);
message.Subject = "Salary Slip Details";
message.Body = "Salary Slip";
message.Attachments.Add(new Attachment(PDFFile));
SmtpClient Client = new SmtpClient("100.100.105.100");
System.Net.NetworkCredential SMTPUserInfo = new System.Net.NetworkCredential("[email protected]", "sa@123");
Client.UseDefaultCredentials = true;
Client.Credentials = SMTPUserInfo;
Client.Send(message);
lblmsg.Text = "Email Send successfully...!";
}
else if (lblEmail.Text == null)
{
lblmsg.Text = "Email ID Not Available";
}
}
catch (Exception ex)
{
Response.Write(ex.ToString());
}
finally
{
conn.Close();
}
}
}
http://www.c-sharpcorner.com/UploadFile/47548d/sending-mail-with-attachment-and-multiple-file-upload-using/