Click here to Skip to main content
15,886,067 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hi
I need to send the information from my database ordre_linie to my email?

C#
private void sendEmail()
     {
         SqlConnection conn = new SqlConnection();
         conn.ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ToString();

         SqlCommand cmd = new SqlCommand();
         cmd.Connection = conn;
         cmd.CommandText = "SELECT ordre_linie_id FROM ordre_linie";


         //Create instance of MailMessage Class
         MailMessage msg = new MailMessage();
         //Assign From mail address
         msg.From = new MailAddress(TextBox_mail.Text);
         msg.To.Add(new MailAddress("my email"));
         msg.Subject = "Ordre fra bruger";

         msg.Body = "Ordre indeholder";

         msg.Body += ordre_linie_id ;

         msg.IsBodyHtml = true;

         SmtpClient SmtpServer = new SmtpClient();

         SmtpServer.Host = "smtp.gmail.com";

         SmtpServer.Port = 587;

         SmtpServer.Credentials = new System.Net.NetworkCredential("my email", "xxxxx");

         SmtpServer.EnableSsl = true;

         SmtpServer.Send(msg);

     }


/Tina
Posted
Updated 23-Oct-13 4:28am
v2
Comments
StM0n 23-Oct-13 7:29am    
Have you checked this "http://www.codeproject.com/Tips/163829/Sending-an-Email-in-C-with-or-without-attachments"
tina_overgaard 23-Oct-13 8:24am    
Do I set my variabel from my database here

cmd.Parameters.Add("@name", SqlDbType;??
tina_overgaard 23-Oct-13 8:25am    
foreach (MailAttachment ma in attachments)
{
mail.Attachments.Add(ma.File);
}
StM0n 23-Oct-13 8:33am    
Mhm... I have to admit, that I'm not quite sure what are you trying to achieve. I thought your problem was sending a mail... but it occurred, that this isn't the problem... could you rephrase your question?

tina_overgaard 23-Oct-13 10:08am    
I need to send the information from my database ordre_linie to my email

your Query will return N number of records so here is a solution i am adding

you have to execute your query and capture the result in datareader

SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
ordre_linie_id= Convert.ToInt64(reader["ordre_linie_id"]);
}
reader.Close();


then you will have to implement for loop .....???

if you want to implement for single record then please specify where condition in your Query.
 
Share this answer
 
Have you noticed, that you never execute your query?
 
Share this answer
 

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