Quantcast
Channel: Active questions tagged email - Stack Overflow
Viewing all articles
Browse latest Browse all 29762

Changing the position of an image in E-mail using C# WinForms

$
0
0

I use the following code to send an email along with an image, the image is not an attachment its simply used to add more detail to the email instead of it being just plain text:

private void button1_Click(object sender, EventArgs e)
    {
        MailMessage mail = new MailMessage();
        mail.To.Add(jTextBox1.TextValue);
        mail.From = new MailAddress("E-mail");

        mail.Subject = "Re, Passport admission";
        mail.IsBodyHtml = true;

            var inlineLogo = new LinkedResource(@"C:\Users\Lenovo\Desktop\c# pictures\eagle.png", "image/png");
                inlineLogo.ContentId = Guid.NewGuid().ToString();

                string body = string.Format(@"<img src=""cid:{0}"" /> <p>Lorum Ipsum Blah Blah</p><p>Lorum Ipsum Blah Blah</p>", inlineLogo.ContentId);


                var view = AlternateView.CreateAlternateViewFromString(body, null, "text/html");
                view.LinkedResources.Add(inlineLogo);
                mail.AlternateViews.Add(view);

        SmtpClient smtp = new SmtpClient();

        smtp.Host = "smtp.gmail.com";
        smtp.Port = 587;
        smtp.EnableSsl = true;

        //has to be a valid email address
        smtp.Credentials = new System.Net.NetworkCredential("E-mail", "Password");
        smtp.Send(mail);
        MessageBox.Show("your email has been sent");


    }

This code works perfectly but i want to change the position of the image in the Email to the middle, right now its to the left. Is there a way to change the position?


Viewing all articles
Browse latest Browse all 29762

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>