Web Forms :: Embed Images In HTML Email With C#?

Apr 6, 2010

Here is my code. What do I need to change to get the images referenced in the HTML to embed?

using
System;
using
System.Data;
using
System.Configuration;
using
System.Web;
using
System.Web.Security;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
System.Web.UI.WebControls.WebParts;
using
System.Web.UI.HtmlControls;
using
System.IO;
using
System.Net.Mail;
public
partial
class
SendEmail1 : System.Web.UI.Page
{
{
}
{
string FileNameToAttache;protected
void Page_Load(object sender,
EventArgs e)protected
void sendButton_Click(object sender,
EventArgs e)SmtpClient smtpClient =
new
SmtpClient();MailMessage message =
new
MailMessage();try
{
message.To.Add(toEmail);
}
MailAddress fromAddress =
new
MailAddress(fromTextBox.Text);string[] toEmails = toTextBox.Text.ToString().Split(';');foreach
(string toEmail
in toEmails) {//MailAddress toAddress = new MailAddress(toTextBox.Text);
message.From = fromAddress;
//message.To.Add(toAddress);
message.Subject = subjectTextBox.Text;
message.IsBodyHtml =
true;
/* Attaching Files Begin */
{
{
FileNameToAttache =
AttachFile1.PostedFile.SaveAs(Server.MapPath(FileNameToAttache));
message.Attachments.Add(
}
}
emailWithAttach.Host =
emailWithAttach.DeliveryMethod =
emailWithAttach.UseDefaultCredentials =
{
{
FileNameToAttache =
AttachFile1.PostedFile.SaveAs(Server.MapPath(FileNameToAttache));
message.Attachments.Add(
}
}
{
{
FileNameToAttache =
AttachFile1.PostedFile.SaveAs(Server.MapPath(FileNameToAttache));
message.Attachments.Add(
}
}
{
{
FileNameToAttache =
AttachFile1.PostedFile.SaveAs(Server.MapPath(FileNameToAttache));
message.Attachments.Add(
}
}
if (AttachFile1.PostedFile !=
null)HttpPostedFile attFile = AttachFile1.PostedFile;int
attachFileLength = attFile.ContentLength;if (attachFileLength > 0)Path.GetFileName(AttachFile1.PostedFile.FileName);new
Attachment(Server.MapPath(FileNameToAttache)));SmtpClient emailWithAttach
= new
SmtpClient();"Localhost";SmtpDeliveryMethod.Network;true;if
(AttachFile2.PostedFile != null)HttpPostedFile attFile = AttachFile2.PostedFile;int
attachFileLength = attFile.ContentLength;if (attachFileLength > 0)Path.GetFileName(AttachFile2.PostedFile.FileName);new
Attachment(Server.MapPath(FileNameToAttache)));if (AttachFile3.PostedFile
!= null)HttpPostedFile attFile = AttachFile3.PostedFile;int
attachFileLength = attFile.ContentLength;if (attachFileLength > 0)Path.GetFileName(AttachFile3.PostedFile.FileName);new
Attachment(Server.MapPath(FileNameToAttache)));if (AttachFile4.PostedFile
!= null)HttpPostedFile attFile = AttachFile4.PostedFile;int
attachFileLength = attFile.ContentLength;if (attachFileLength > 0)Path.GetFileName(AttachFile4.PostedFile.FileName);new
Attachment(Server.MapPath(FileNameToAttache)));
/* Attaching Files END */
message.Body =
smtpClient.Host =
smtpClient.Send(message);
resultLabel.Text =
}
{
resultLabel.Text =
}
}
{
}
}
"<html><head><title>" +
HttpUtility.HtmlEncode(subjectTextBox.Text) +"</title></head><body style='background-color:#edf8ff;'><div
style='width:600px;'><table width='600' align='center' style='background-color:#ffffff;'>" +
"<img src="[URL]/>" +"<tr><td colspan='2'style='width:500px;'><p>"
+ HttpUtility.HtmlEncode(greetingTextBox.Text) +
"</p></td></tr><br />" +"<tr><td colspan='2'style='width:500px;'><p>"
+ HttpUtility.HtmlEncode(createTextBox.Text) +
"</p></td><img src="[URL]" /></tr><br />" +"<tr><td
colspan='2'style='width:500px;'><p>" + HttpUtility.HtmlEncode(closingTextBox.Text) +
"</p></td></tr>" +"<tr><td><img src="[URL]"
/></td></tr>" +"</table></div></body><html>";"Localhost";"Email
sent! <br />";catch (Exception
ex)"Couldn't Send the Message!";protected
void clearButton_Click(object sender,
EventArgs e)

View 6 Replies


Similar Messages:

Web Forms :: Embed Images In Email

Mar 31, 2010

In one of my ASP.NET page I have to send email to the users. I did this using System.Net.Mail namespace. The problem is if I want to send images I used the <img src=""/> to display them in my email. But now some of images are not hosted anywhere and I still want ti send the email with images. I want to embed them in my mail. Is there any way to do this in c#.

View 6 Replies

Embed Image Into HTML And Send In Email?

May 7, 2010

I would like to embed a picture into a html and send it in email. How can do so.

View 2 Replies

How To Embed HTML Tag While Sending Email Using SmtpMail

Jan 31, 2010

how to embed HTML tag while sending email using SmtpMail?I am using below code. Can anyone tell me where I went wrong?

MailMessage message = new MailMessage();
message.From = new MailAddress("sender@fgk.com");
message.To.Add(new MailAddress("receiver@fgk.com"));
message.Subject = "This is my subject";
message.Body = "This is the <b>content</b> <br /> <img alt=Logo src=../Images/logo.jpg align=left />";
message.IsBodyHtml = true;

View 5 Replies

Web Forms :: Sending Html Page - Images Are Not Send In Email?

Aug 9, 2010

i want to send html page with email.In html pages images are shown ,stored in databse and retrived by using generic handler. I have tried to call handler using javascript function.but images are not send in email.

View 4 Replies

Web Forms :: How To Send HTML Page As Email With Images And Text

Dec 24, 2012

how to send html page as email with images and text in asp.net c#

View 1 Replies

Web Forms :: How To Embed Chart In Email Body And Send Email

May 7, 2015

how to display Chart in Email body and excel attachment.

View 1 Replies

Web Forms :: Embed Image In Email Based On URL

Dec 27, 2010

I have used Embed image in Email based on [URL]Image will not show in email. But it become an attachment.

public void sendEmail(string mailTo, string mailCC, string contentFileName, Hashtable parameters)
{
string s = Dns.GetHostName();
MailAddress fromAddress = new System.Net.Mail.MailAddress(RPUser.getAppSetting(WEB_SMTP_USER_EMAIL));
System.Net.Mail.MailMessage mailMessage = new System.Net.Mail.MailMessage();
mailMessage.From = fromAddress;
mailMessage.To.Add(mailTo);
if (mailCC != "")
mailMessage.To.Add(mailCC);
string Body = getMailhtml(contentFileName, parameters);
//mailMessage.Body = Body;
System.Net.Mail.AlternateView htmlView = System.Net.Mail.AlternateView.CreateAlternateViewFromString(Body, null, "text/html");
IDictionaryEnumerator en = parameters.GetEnumerator();
while (en.MoveNext())
{
string parameterStr = en.Key.ToString();
if (parameterStr.Contains("cid:"))
{
//string path = System.Web.HttpContext.Current.Request.Url.AbsoluteUri.Remove(System.Web.HttpContext.Current.Request.Url.AbsoluteUri.LastIndexOf('/') + 1) + en.Value.ToString();
string path = @"D:ProjectsRPPortalBLRPPortal" + en.Value.ToString();
LinkedResource logo = new LinkedResource(path);
logo.ContentId = parameterStr;
htmlView.LinkedResources.Add(logo);
}
}
mailMessage.AlternateViews.Add(htmlView);
if (parameters[EMAIL_SUBJECT] != null) mailMessage.Subject = parameters[EMAIL_SUBJECT].ToString();
mailMessage.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.Host = RPUser.getAppSetting(WEB_SMTP_HOST);
smtp.Port = Convert.ToInt32(RPUser.getAppSetting(WEB_SMTP_PORT));
if (Convert.ToBoolean(RPUser.getAppSetting(WEB_SMTP_SSL)))
smtp.EnableSsl = true;
else
smtp.EnableSsl = false;
smtp.Credentials = new System.Net.NetworkCredential(RPUser.getAppSetting(WEB_SMTP_USERNAME), RPUser.getAppSetting(WEB_SMTP_PASSWORD));
try { smtp.Send(mailMessage); }
catch (Exception) { }
}

View 3 Replies

Web Forms :: How To Embed Image In Email Message

Jan 14, 2010

I have an automated web report i send to users on a regular basis. The report is a web page template that i replace the main pieces of data with the current days data. In this case the reporting is shown in the form of a chart. Everything seems to work fine except for one image that does not show up in the email report. see the code below

[Code]....

Each time i send the email it goes throught with all the other images except the one above. When i view the email as a web page however the image does show up in the browser. This leads me to believe that there is a limitation with viewing embeded images in Outlook 2007. I have tried to follow suggestions like the one described here, [URL] but it does not seem to work. Can somebody tell me how to get my images to show up in an email message using outlook 2007?

View 11 Replies

Web Forms :: Embed Image In Automated Email

Feb 6, 2010

I have a website which needs to send automated emails. I have the emailing set up fine but what I haven't managed to do is embed an image in the messages. I have tried the following code :

[Code]....

All this does is is place the standard "box with red cross" in the email body and attach a '.dat' file.

View 3 Replies

Embed Images Into Asp Page

Jul 8, 2010

I have an application in that i m placed one drop down box.Now i want to show some image and other details according to that drop down item in asp page ..I am assigning drop down items in C # .Now the requirment is like on that time click need to show corresponding image on asp page. how to retreive images according to the drop down item value.

View 9 Replies

Web Forms :: Embed Binary Image From Database In Message Body And Send Email

May 7, 2015

I have been trying to add BLOB Image from Oracle Database table to Email content as HTML table elemnt.

<table style='width: 100%; font-weight: bold;'>
<tr style="border-style: groove; font-size: 14px; font-weight: bold; background-color: #45a297;">
<td colspan="2" style="font-size: 8px; font-family: Verdana; font-weight: bold; padding-left: 0px; color: white; font-size: 16px; text-align: center">Flight</td>
</tr>

[CODE]..

I am getting my data in Email except Image in mail content.

View 1 Replies

Web Forms :: Embed HTML In ASPX But Not IFRAME?

Apr 23, 2010

i need Embed and HTML page with ASPX page ....

the html page is a simple page which include "<html><head><body> .... Some Content ....etc".

and also the aspx page is a simple also, so when the customer open "index.aspx" this will open aspx page but with HTML Content.

i dont need to use IFRAMES,

the code for asp.net will read the HTML content and put it in aspx in run time.

View 5 Replies

Embed Image In Email With ASP

Feb 8, 2010

i did this code to embed an image in an email:

[Code]....

i did this code by seeing the how do i videos. while running this code,when i clicked the send email button i get the error in this particular line:

[Code]....

View 3 Replies

VS 2005 Embed Image In Email

Feb 8, 2010

i did this code to embed an image in an email:

Code:

If FileUpload1.HasFile Then
Dim emailMessage As System.Net.Mail.MailMessage = New System.Net.Mail.MailMessage
emailMessage.From = New System.Net.Mail.MailAddress(System.Configuration.ConfigurationSettings.AppSettings("txt"))
emailMessage.To.Add(txtTo.Text.Trim())
emailMessage.Subject = txtSubject.Text.Trim()
Dim plainTextView As System.Net.Mail.AlternateView = System.Net.Mail.AlternateView.CreateAlternateViewFromString(txtBody.Text.Trim(), Nothing, "text/plain")
Dim htmlView As System.Net.Mail.AlternateView = System.Net.Mail.AlternateView.CreateAlternateViewFromString(txtBody.Text.Trim() + "<img src=cid:HDIImage>", Nothing, "text/html")
Dim imageResource As New System.Net.Mail.LinkedResource(FileUpload1.PostedFile.FileName)
imageResource.ContentId = "HDIImage"
htmlView.LinkedResources.Add(imageResource)
emailMessage.AlternateViews.Add(plainTextView)
emailMessage.AlternateViews.Add(htmlView)
Dim smtpClient As System.Net.Mail.SmtpClient = New System.Net.Mail.SmtpClient
Try
smtpClient.Send(emailMessage)
Catch smtpexc As System.Net.Mail.SmtpException
Catch ex As Exception
End Try
End If

i am getting the runtime error:

Could not find the file how to solve this?

View 14 Replies

Assemblies - Embed Js / Css Images Into Separate Assembly To Read From Website

Sep 3, 2010

I'd like to create a class library project where embed resources like js, css and maybe image files. I would compile it and copy the dll into the bin folder of my web site to include the resources into my pages with GetWebResourceUrl.

I tried with an assembly that have no .cs files, but it doesn't seem to work, I can't see the namespace of the assembly in the web project.

View 1 Replies

Can Embed The File In HTML

Jan 27, 2011

I have downloaded a new font file. I want to use this font style in my html page. How do i embed the file in HTML?

View 2 Replies

C# - Embed String In The Html?

Feb 2, 2010

Asp.net c# I am using the below code..

<%String h = "hello";%>
<!-- "wall_com_insert.aspx?Tid=" + Application.Get("Tid");-->
<div id="content_sr_comment" style="height: auto"> <asp:Label ID="Label8"
runat="server" Text="<%=h%>" ></asp:Label>
</div>

But I am getting the output..

output displayed on the label: "<%=h%>"

View 3 Replies

MVC :: Embed An Image In Html.ActionLink?

Feb 28, 2011

I want to embed an image in Html.ActionLink instead of using a text.

Here is what I am using:

<li> <%: Html.ActionLink("4WD", "Browse4WD", "Vehicles", new { categoryName = "4WD" }, null)%></li>

The link display the text "4WD" (1st parameter).

I want to display the image instead "4WD".

I have an image stored under Content folder, I tried this:

<li>
<a href= "<%= Url.Action("Browse4WD", "Vehicles")%>" >
<img src="<%= ResolveUrl("~/Content/4WDImageGroup.jpg")%>" />
</a>
</li>

But the web page did not display image but only the 'cross'. Looks like cannot find the path of the image.

View 4 Replies

Vb.net - Embed The Html Code In Webform?

Dec 22, 2010

How to embed html code and display the result according to the html code pasted in the textbox multiline asp.net webform..

The example of this is www.orkut.com scrapbook ...

when any body post a graphic comment then it would embed the html coding in scrapbook and he results will be displayed i scrapbook on button submit click ...

Here is the picture what i want -- i want code snippet for this

View 1 Replies

Web Forms :: Sending An Email As An HTML Email

Jun 1, 2010

I have the below script to get a Web Page's html and add it as a string to the mail.body property of the mail message that I have created. However, if the webpage is larger then several KBs, it cause a StackOverflowException to fire.

[Code]....

Is there a simple way to just tell the mail message to use a link like "a.com/default.aspx" for the mail message body?

View 4 Replies

AJAX :: Embed Spell Checker In Html Editor

Jan 29, 2010

I am using ajax html editor, is it possible to embed a spell checker?

View 8 Replies

Web Forms :: Send Email With Images And Controls?

Mar 20, 2010

I know how to send mail. but i cant send a mail with images inside. also i need to display the repeater control's content inside my mail. Embedded image procedure not works for me. plz provide some sample code or links. i'm looking for C# code.

View 7 Replies

Web Forms :: Interleave Links And Images Into Email Body?

Nov 16, 2010

I Use SmtpClient to send email, but I need to interleave some links and logo images into email body. How can I do that? is it as simple as adding <a ...> links and <img ...> tags into body content? how to make confirmation links and confirmation emails?

View 1 Replies

Properties Of .NET Images And What Are Of HTML Images

Jan 18, 2011

I know that HTML is client sided and ASP.NET is server sided. The question is should I use HTML or ASP.NET Images and whats the difference?What are the properties of ASP.NET images and what are of HTML images.

View 3 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved