I'm sending an image through web form the image is displayed well into gmail ,yahoo etc.
But i'm not able to view that image when I send it on Outlook
what would be wrong please help.
Code:
//Variable mg have a html code with 'cid:uniqueId1’ calls image from function SendMail12
void birthday()
{
Coonection con = new Coonection();
sql = "select es.PORTNO,es.SERVERNAME,es.EMAILID,es.PASSWORD,e.efrom,e.SerNo,e.eto,e.ecc,e.emessage,e.eflag,e.EmpID,e.FIRSTNAME,e.LASTNAME,e.DeptName,e.FromDate,e.Todate,e.Reason from EMAILSETTING es,EmailSender e";
SqlDataAdapter da = new SqlDataAdapter(sql, con.GetConnection());
DataSet ds = new DataSet();
da.Fill(ds);
string sub = "Message";
int portnum, n,sn;
string servername1, passwo, account, t, ecc, mg, flage,mg2;
sql = "select count(srno)from EmailSender";
SqlCommand cmd = new SqlCommand(sql, con.GetConnection());
// dr = cmd.ExecuteReader();
n = Convert.ToInt32(cmd.ExecuteScalar());
//while (i)
//{
for (int i = 0; i < n; i++)
{
if (ds.Tables[0].Rows.Count > 0)
{
portnum = Convert.ToInt32(ds.Tables[0].Rows[0]["PORTNO"].ToString());
servername1 = ds.Tables[0].Rows[0]["SERVERNAME"].ToString(); //Table(0).Rows(0)("SmtpServerName").ToString();
account = ds.Tables[0].Rows[0]["EMAILID"].ToString();
passwo = ds.Tables[0].Rows[0]["PASSWORD"].ToString();
t = ds.Tables[0].Rows[i]["eto"].ToString();
ecc = ds.Tables[0].Rows[i]["ecc"].ToString();
mg2 = ds.Tables[0].Rows[i]["emessage"].ToString();
flage = ds.Tables[0].Rows[i]["eflag"].ToString();
sn = Convert.ToInt32(ds.Tables[0].Rows[i]["SerNo"].ToString());
if (flage == "N" && mg2 == "Wish You a Very Happy Returns of the Day.<P> From - Daccess Security Systems Pvt ")
{
mg = " <html> " +
"<body background= 'meet.jpg'>" +
"<head> " +
"<title>Untitled Document</title> " +
"<meta content='text/plain; charset=us-ascii' http-equiv='Content-Type' />" +
"<style type='text/css'> " +
".style1 { " +
"font-family: Arial, Helvetica, sans-serif; " +
"font-weight: bold; " +
"font-size: 18px; " +
"color: #3333CC; " +
"} " +
".style3 { " +
"font-family: 'Times New Roman', Times, serif; " +
"color: #003399; " +
"} " +
".style4 { " +
"font-family: Arial, Helvetica, sans-serif; " +
"font-weight: bold; " +
"font-size: 12px; " +
"} " +
".style11 { " +
"color: #1A588D; " +
"font-family: 'Times New Roman', Times, serif; " +
"font-weight: bold; " +
"} " +
".style15 { " +
"color: #1A588D; " +
"font-weight: bold; " +
"} " +
".style18 {color: #FFFFFF; font-weight: bold; } " +
"body { " +
"margin-top: 1px; " +
"margin-left: 1px; " +
"margin-right: 1px; " +
"margin-bottom: 1px; " +
"} " +
"</style> " +
"<link href='Untitled-1.htm' id='1' title='view'> " +
"<script language='JavaScript' type='text/JavaScript'> " +
"function MM_reloadPage(init) { " +
"if (init==true) with (navigator) {if ((appName=='Netscape')&&(parseInt(appVersion)==4)) { " +
"document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }} " +
"else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload(); " +
"} " +
"MM_reloadPage(true); " +
"</script> " +
"<style type='text/css'> " +
"a:link { " +
"text-decoration: none; " +
"} " +
"a:visited { " +
"text-decoration: none; " +
"} " +
"a:hover { " +
"text-decoration: none; " +
"} " +
"a:active { " +
"text-decoration: none; " +
"} " +
".style20 {font-size: 12px} " +
"</style></head> " +
"<body> " +
"<p class='style1'><img src='cid:uniqueId' width='145' height='111'></p> " +
"<table border= 1 align ='left'>" +
"<tr>" + "<td>Employee ID :" + "</td>" +
"<td>" + ds.Tables[0].Rows[i]["EmpID"].ToString() + "</td>" +
"</tr>" +
"<tr>" + "<td>Employee Name :" + "</td>" +
"<td>" + ds.Tables[0].Rows[i]["FIRSTNAME"].ToString() + " " + ds.Tables[0].Rows[i]["LASTNAME"].ToString() + "</td>" +
"</tr>" +
"<tr>" + "<td>Department :" + "</td>" +
"<td>" + ds.Tables[0].Rows[i]["DeptName"].ToString() + "</td>" +
"</tr>" +
"<tr>" + "<td>Message :" + "</td>" +
"<td>" + ds.Tables[0].Rows[i]["emessage"].ToString() + "</td>" +
"</tr>" +
"<tr>"+
"<td>"+
"<pre align='left' class='style3'><strong><img src='cid:uniqueId1' width='286' height='177'></strong></pre> " +
"<pre align='left' class='style4'> <a name='t'></a> Please do not reply to this email.</pre>" +
"<p align='left' class='style3'> </p> " +
"</td>"+"</tr>"+"</table>"+
"</body> " +
"</html> ";
if (flage == "N" && mg2 == "Wish You a Very Happy Returns of the Day.<P> From - Daccess Security Systems Pvt ")
{
SendMail12(account, passwo, t, sub, mg, ecc, servername1, portnum);
sql = "Update EmailSender set eflag ='Y' where SerNo = '" + sn.ToString() + "'";
SqlCommand cmd4 = new SqlCommand(sql, con.GetConnection());
cmd4.ExecuteNonQuery();
}
}
}
else
{
servername1 = "";
portnum = 0;
account = "";
passwo = "";
MessageBox.Show("Email Setting Is Not Stored");
}
}
}
// Send mail function
public static bool SendMail12(string gMailAccount, string password, string to, string subject, string message, string cc, string server, int port)
{
try
{
NetworkCredential loginInfo = new NetworkCredential(gMailAccount, password);
MailMessage msg = new MailMessage();
msg.From = new MailAddress(gMailAccount);
msg.To.Add(new MailAddress(to));
string[] s;
s = cc.Split(';');
for (int i = 0; i < s.Length; i++)
{
msg.CC.Add(new MailAddress(s[i].ToString()));
}
msg.Subject = subject;
msg.Body = message;
msg.IsBodyHtml = true;
SmtpClient client = new SmtpClient();
client.Host = server;
client.Port = port;
client.Timeout = 100000;
client.EnableSsl = true;
client.UseDefaultCredentials = true;
client.Credentials = loginInfo;
string palinBody = "Plain text content, viewable by those clients that don't support html";
AlternateView plainView = AlternateView.CreateAlternateViewFromString(palinBody, null, "text/plain");
string htmlBody = message;
AlternateView htmlView = AlternateView.CreateAlternateViewFromString(htmlBody, null, "text/html");
//create the AlternateView for embedded image
AlternateView imageView = new AlternateView("D:\\Aniket Work\\New Folder Update\\EmailSender\\EmailSender\\images\\Daccess-logo.gif", MediaTypeNames.Image.Gif);
imageView.ContentId = "uniqueId";
imageView.TransferEncoding = TransferEncoding.Base64;
AlternateView imageView1 = new AlternateView("D:\\Aniket Work\\New Folder Update\\EmailSender\\EmailSender\\images\\birthday1images.jpg", MediaTypeNames.Image.Jpeg);
imageView1.ContentId = "uniqueId1";
imageView1.TransferEncoding = TransferEncoding.Base64;
//add the views
msg.AlternateViews.Add(plainView);
msg.AlternateViews.Add(htmlView);
msg.AlternateViews.Add(imageView);
msg.AlternateViews.Add(imageView1);
client.Send(msg);
return true;
}
catch (Exception e)
{
return false;
}
}
You should be giving absolute paths to your resources
e.g.
in above code, your body background should be something like
<body background= 'http://yourdomain.com/meet.jpg'>
same thing applies to your image tag or you can have inline content disposition
EDIT
Do you see something like this when you view the mail?
Related
I get this error:
System.Data.SqlClient.SqlException: 'Must declare the scalar variable "#refSlips".'
Code:
SqlConnection con = new SqlConnection(connectionString);
SqlCommand aaa = new SqlCommand("INSERT INTO ConsultationTB VALUES('" + consultationTb.Text + "','" + dateTb.Text + "','" + bodytempTb.Text + "','" + paccodeTb.Text + "', #refSlips ", con);
string RadButt = string.Empty;
if (ForAdmission.Checked)
{
RadButt = "For Admission";
}
else if (ForLabTest.Checked)
{
RadButt = "For Laboratory Test";
}
else if (BothRb.Checked)
{
RadButt = "Both";
}
else if (NotAppRb.Checked)
{
RadButt = "Not Applicable";
}
con.Open();
aaa.ExecuteNonQuery();
con.Close();
getCONNO();
ForAdmission.Checked = false;
ForLabTest.Checked = false;
BothRb.Checked = false;
NotAppRb.Checked = false;
[ + "', #refSlips)" , con);] the problem was the parenthesis after refslips.
I have this code om my View. And this is work good.
... onclick="location.href = '#Url.Action("Plan", "Care", new {Area = "HomeC"})'"><img src="~/Content/images/dash/Care.PNG"
How Can I do the same code with Html.Raw?
I tried this
grid.Column(columnName: "Name", header: "", format: #<text>#(item.ListStatus == 1 ? Html.Raw("<button class='btn btn-default btn-plan' title='Care' onclick='location.href = " + "'" + Url.Action("Plan", "Care", new {Area = "HomeC"}) + "''>" +
"<img src='/Content/images/dash/Care.PNG' class='img-plan' data-interlocutorid=" + item.UserId + " " + "data-interlocutorname=" + item.Name + " " + ">" +
"</button>") : Html.Raw(""))
</text>),
With image all good, but link doesn't work.
Change the single-quotes around your Url.Action(...) to double-quotes instead.
That is, change this portion:
onclick='location.href = " + "'" + Url.Action("Plan", "Care", new {Area = "HomeC"}) + "''
to this:
onclick='location.href = " + "\"" + Url.Action("Plan", "Care", new {Area = "HomeC"}) + "\"'
This will change the rendered output from:
onclick='location.href = '/Care/Plan?Area=HomeC''
to:
onclick='location.href = "/Care/Plan?Area=HomeC"'
onclick=" + "location.href=" + "'" + Url.Action("Plan", "Care", new {Area = "HomeC"}) + "'" + ">"
This is work good.
I have problem that onserverclick attribute does not work ,the method which assigned to it does not trigger.
string strTr = "";
for (int i = 0; i < adminuserlist.Count; i++)
{
strTr += string.Format("<tr id=\"tr\">" +
" <td>{0}</td> " +
" <td>{1}</td> " +
" <td>{2}</td> " +
" <td>{3}</td> " +
" <td>{4}</td> " +
" <td>{5}</td> " +
" <td>{6}</td> " +
"<td class=\"col-lg-2\">" +
" <a href=\"#\" id=" + i +
"runat=\"server\" onServerClick=\"MyFuncion_Click\"
class=\"table-icontoolbar\" data-toggle=\"tooltip\" data-
placement=\"top\" title=\"Edit\"> " +
" <img
src=\"../images/icon-edit.png\"></a> " +
" <a href=\"#\"
runat=\"server\" onClick=\"bll();\"
onServerClick=\"MyFuncion_Click2\" class=\"table-icontoolbar\"
data-toggle=\"tooltip\" data-placement=\"top\"
title=\"Delete\">" +
" <img
src=\"../images/icon-delete.png\"></a>" +
" </td> " +
" </tr>",
adminuserlist[i].AdminUserName,
adminuserlist[i].AdminUserPassword,
adminuserlist[i].AdminUserEmail,
adminuserlist[i].AdminUserType, adminuserlist[i].IsActive,
adminuserlist[i].isDeleted,
adminuserlist[i].CreatedOn);
tbodyAdminUserView.InnerHtml = strTr;
}
and this the function which should be triggered:
public void MyFuncion_Click(Object sender, EventArgs e)
{
Label1.Text = "vvvv";
}
I have a page that which is an exam page,it selects all MCQ questions with their answers...
and in server side page load i add div.innerHtml += "html tags " + question + radio buttons containing answers and it keeps selecting from database till all questions are rendered in client side, the thing is i add all these questions and tags in form and in its end there is a input submit button which should submit all radio buttons values but even if i set form action i cant get the radio buttons values...
Here is some code :
using (SqlDataReader sr1 = command1.ExecuteReader())
{
cc.InnerHtml = "<form id=\"form2\" name=\"form2\" method=\"post\" action=\"\">";
while (sr1.Read())
{
i++;
iString = i.ToString();
questionText = sr1["text"].ToString();
question_first_wrong_answer = sr1["first_wrong_answer"].ToString();
question_second_wrong_answer = sr1["second_wrong_answer"].ToString();
question_right_answer = sr1["right_answer"].ToString();
questionValue = (int)sr1["value"];
c = answerPos.Next(0, 10);
cc.InnerHtml += "<span>" + iString + "- " + questionText +"</span>"
+ "<br />"
+ "<table style=\"width:77%; margin-left: 47px;\">"
+ "<tr>"
+ " <td style=\"width: 210px\">"
+ " <input type=\"radio\" name=\"question" + iString + "a\" value=\"" + question_first_wrong_answer + "\" />" + question_first_wrong_answer + "</td>"
+ "<td style=\"width: 210px\">"
+ "<input type=\"radio\" name=\"question" + iString + "a\" value=\"" + question_second_wrong_answer + "\" />" + question_second_wrong_answer + "</td>"
+ "<td style=\"width: 210px\">"
+ "<input type=\"radio\" name=\"question" + iString + "a\" value=\"" + question_right_answer + "\" />" + question_right_answer + "</td>"
+ "</tr>"
+ "</table>"
+ "<br />";
}
sr1.Close();
cc.InnerHtml += "<input id=\"Submit1\" type=\"submit\" value=\"Submit\" />"
+ "</form>";
}
Do not Use InnerHtml. Its Wrong.
Use Inbuild HtmlPage Class
Use Like this for Example
Page.Controls.Add(
new LiteralControl(#"<html>\r\n<body>\r\n
<h1>Welcome to my Homepage!</h1>\r\n"));
HtmlForm Form1 = new HtmlForm();
Form1.ID = "Form1";
Form1.Method = "post";
Form1.Controls.Add(
new LiteralControl("\r\nWhat is your name?\r\n"));
TextBox TextBox1 = new TextBox();
TextBox1.ID = "txtName";
Form1.Controls.Add(TextBox1);
Form1.Controls.Add(
new LiteralControl("\r\n<br />What is your gender?\r\n"));
DropDownList DropDownList1 = new DropDownList();
DropDownList1.ID = "ddlGender";
ListItem ListItem1 = new ListItem();
ListItem1.Selected = true;
ListItem1.Value = "M";
ListItem1.Text = "Male";
DropDownList1.Items.Add(ListItem1);
ListItem ListItem2 = new ListItem();
ListItem2.Value = "F";
ListItem2.Text = "Female";
DropDownList1.Items.Add(ListItem2);
ListItem ListItem3 = new ListItem();
ListItem3.Value = "U";
ListItem3.Text = "Undecided";
DropDownList1.Items.Add(ListItem3);
Form1.Controls.Add(
new LiteralControl("\r\n<br /> \r\n"));
Button Button1 = new Button();
Button1.Text = "Submit!";
Form1.Controls.Add(Button1);
Form1.Controls.Add(
new LiteralControl("\r\n</body>\r\n</html>"));
Controls.Add(Form1);
Remove the server form element (<form runat="server" ). If that is present, this new form is discarded.
Also you are using the same name for different input controls.
name=\"question" + iString + "a\" value=\""
So you need to have unique names for the radio too.
I have a xml file that changed when i update some values, and i'm trying to read it from javascript in asp.net.
But once i run the project, every time i try to read the xml file, the file is the same from the begining...
this is my javascript code that i have in server side
script = "function OnClientDragEnd(dock, args)" +
"{" +
" req = false; " +
" var isIE = false;" +
// branch for native XMLHttpRequest object
" if(window.XMLHttpRequest && !(window.ActiveXObject)) {" +
" try {" +
" req = new XMLHttpRequest();" +
" } catch(e) {" +
" req = false;" +
" }" +
// branch for IE/Windows ActiveX version
" } else if(window.ActiveXObject) {" +
" try {" +
" req = new ActiveXObject('Msxml2.XMLHTTP');" +
" } catch(e) {" +
" try {" +
" req = new ActiveXObject('Microsoft.XMLHTTP');" +
" } catch(e) {" +
" req = false;" +
" }" +
" }" +
" }" +
" if(req) {" +
" req.onreadystatechange = function(){processReqChange(dock,args)};" +
" req.open('GET', 'Config.xml', false);" +
" req.send('');" +
" }" +
"}" +
"function processReqChange(dock,args) {" +
// only if req shows "loaded"
" if (req.readyState == 4) {" +
// only if "OK"
" if (req.status == 200) {" +
// ...processing statements go here...
" var iiii = req.responseXML.getElementsByTagName('Object');alert(iiii.length);" +//Value stays the same after xml have changed
" } else {" +
" alert('There was a problem retrieving the XML data: ' + req.statusText);" +
" }" +
" }" +
"}";
ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "PositionChanged", script, true);
This code is in http://developer.apple.com/internet/webcontent/xmlhttpreq.html
What do i need to do for get always the xml file updated
IE has a habit of caching AJAX requests. Try something like this:
Date d = new Date();
req.open('GET', 'Config.xml?_' + d.getTime(), false);
this will append the number of milliseconds since 1970 to each request, forcing IE to fetch a new version of the XML.