Click here to Skip to main content
15,890,557 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a Table that contains student Details. I need to send some Word Document Files through Mails to the Students.

I Successfully sent the Documents to all the students but the problem is only the First Student received the Document and the Data in the Document and the remaining students received the Document but the Data is Missing it shows Blank page.

for Example I have some Mail Ids
list of mail Ids
abc@xyz.com
def@xyz.com
.
.
.
.

venkatkumar744@gmail.com had received the Document and the Data in the Document

sandeep.kazipeta@gmail.com had received Document but the Data in the Document shows empty.


The Html Code is

<tr>

<td><asp:Label id="lbloracle11gDBA" runat="server" Text="Oracle 11g DBA"></asp:Label></td>
<td><asp:TextBox ID="txtoraclebatchid" runat="server" 
     ontextchanged="txtoraclebatchid_TextChanged" AutoPostBack="true"></asp:TextBox></td>
<td><asp:TextBox ID="txtoraclestdt" runat="server" ></asp:TextBox></td>
<td><asp:TextBox ID="txtoracleendt" runat="server" ></asp:TextBox></td>
<td><asp:TextBox ID="txtoracletimings" runat="server" ></asp:TextBox></td>
<td><asp:FileUpload ID="upload" runat="server" /></td>
<td><asp:Button ID="btnoraclesend" runat="server" Text="Send"                 onclick="btnoraclesend_Click" /></td>

</tr>




.cs file code

using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Net.Mail;


public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    
    protected void btnoraclesend_Click(object sender, EventArgs e)
    {


        SqlConnection conn = new SqlConnection();
        conn.ConnectionString = "Data Source=xxxxx; User Id=xxxxx; Password=xxxxxx; Initial Catalog=xxxxxxx; Integrated Security=SSPI;";
        conn.Open();


        SqlCommand cmd = new SqlCommand();
        cmd.Connection = conn;
        cmd.CommandText = "select EMail_1 from Student_Info where Branch_Code='ap' and Student_ID in(select Student_ID from Admissions where Branch_Code='ap' and Batch_ID='" + txtoraclebatchid.Text + "')";
        cmd.CommandType = CommandType.Text;

        SqlDataAdapter da = new SqlDataAdapter(cmd);
        da.SelectCommand = cmd;
        DataSet ds = new DataSet();
        da.Fill(ds);
             

        if (ds.Tables[0].Rows[0][0] != null)
        {
            int count = ds.Tables[0].Rows.Count;

            for (int i = 0; i < count; i++)
            {
                
                MailMessage mm = new MailMessage();
                mm.To.Add(ds.Tables[0].Rows[i][0].ToString());
                mm.From = new MailAddress("xxxxxxxxxx");
                mm.Subject = "Asp.net Test Email";
                                
               
           if (upload.HasFile)
          {
              mm.Attachments.Add(new Attachment(upload.PostedFile.InputStream, upload.FileName));
          }
                      
                
                mm.Body = "Hello world";
                SmtpClient s = new SmtpClient("smtp.xxxxxxxxx.com");
                s.Send(mm);
                Response.Write("Email Sent");

            }
            
        }
                
        conn.Close();
        

    }
}




Please tell me the solution.......................
Posted
Updated 17-Jul-13 22:49pm
v2
Comments
Venkat Kumar chigulla 18-Jul-13 6:13am    
is anybody there to help me...?

please

1 solution

Not really sure, looks like a problem with that line:
mm.Attachments.Add(new Attachment(upload.PostedFile.InputStream, upload.FileName));
You create an Attachment from a Stream. Afterwards the stream would be at its end. When you create the attachment for the next mail again, the stream has not been reset to its start position.
I'd suggest to save the stream to a temporary file first (before looping thro the students' list), then create the attachments from the file instead.
Otherwise, the stream could be set back to its origin (if that type of stream does allow to do so).
 
Share this answer
 
Comments
Venkat Kumar chigulla 19-Jul-13 2:19am    
I,m trying to place the file in a Temporary file, i could not get it, will you please tell me how to place it

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900