|
Good Morning All
I have the Following code that sends an e-mail, let me first post the markup and the code behind. The following is the markup of my page
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
To <asp:TextBox ID="txtto" runat="server" Width="325px"></asp:TextBox><br />
<br />
From <asp:TextBox ID="txtFrom" runat="server" Width="326px"></asp:TextBox><br />
<br />
CC: <asp:TextBox ID="txtcc" runat="server" Width="326px"></asp:TextBox><br />
<br />
Subject:
<asp:TextBox ID="txtsubject" runat="server" Width="326px"></asp:TextBox><br />
Body :<br />
<asp:TextBox ID="txtbody" runat="server" Height="86px" Width="314px"></asp:TextBox><br />
<br />
Port:
<asp:TextBox ID="txtport" runat="server" Width="127px"></asp:TextBox><br />
<br />
Host
<asp:TextBox ID="txthost" runat="server" Width="127px"></asp:TextBox><br />
<br />
<asp:Button ID="btnSend" runat="server"
OnClick="btnSend_Click" Text="Send" />
<asp:Button ID="btnCancel" runat="server" Text="Cancel" /><br />
<br />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label></div>
</form>
</body>
</html>
and i have a Function that sends the e-mail like this
private static string SendEmail(String from, string to, string cc,int port, string subject, string message,String Host)
{
System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
mail.From = new System.Net.Mail.MailAddress(from,"Test E-mail");
mail.Subject = subject;
mail.Body = message;
mail.IsBodyHtml = false;
System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient();
smtp.Port = port;
smtp.Host = Host;
smtp.Credentials = new System.Net.NetworkCredential("administrator", "skskssk");
try
{
smtp.Send(mail);
return "Mail sent successfully!";
}
catch (Exception ex)
{
Exception ex2 = ex;
string errorMessage = string.Empty;
while (ex2 != null)
{
errorMessage += ex2.ToString();
ex2 = ex2.InnerException;
}
return errorMessage;
}
}
and in my button send we have the following
protected void btnSend_Click(object sender, EventArgs e)
{
Label1.Text = SendEmail(txtFrom.Text, txtto.Text, txtcc.Text, Convert.ToInt32(txtport.Text), txtsubject.Text,txtbody.Text,txthost.Text);
}
I have entered the Following in the Required Fields when i test the application
To: Vuyiswa@its.co.za
From:Vuyiswa@its.co.za
CC:vuyiswamb@gmail.com
Subject: This is the Test for the mail in o!booking System
BodyIf you Receive this e-mail Please confirm the receipt of this e-mail
Port : 25
Host: mailserver.Vuyiswa.local
When i run my Application and clicking on the send button , i get the Following Error
System.InvalidOperationException: A recipient must be specified. at System.Net.Mail.SmtpClient.Send(MailMessage message) at _Default.SendEmail(String from, String to, String cc, Int32 port, String subject, String message, String Host) in c:\Vuyiswa\Email_test\Default.aspx.cs:line 51
Thanks
Vuyiswa Maseko,
Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers."
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.somee.com
http://www.vuyiswamaseko.tiyaneProperties.co.za
vuyiswa@its.co.za
http://www.itsabacus.co.za/itsabacus/
|
|
|
|
|
Hi
Vuyiswa Maseko wrote: System.InvalidOperationException: A recipient must be specified
As suggested by error and looking at your code i found that you have not add the recipient whom you want to send the mail.I think you miss that
Just Add
mail.To = new System.Net.Mail.MailAddress(to,"Test E-mail");
himanshu
|
|
|
|
|
Thanks a lot for reminding me that part. i have added it and i get a new Error
System.Net.Mail.SmtpException: Syntax error, command unrecognized. The server response was: Microsoft Exchange Server 2003 POP3 server version 6.5.7638.1 (Mailserver.its.local) ready. at System.Net.Mail.SmtpConnection.GetConnection(String host, Int32 port) at System.Net.Mail.SmtpTransport.GetConnection(String host, Int32 port) at System.Net.Mail.SmtpClient.GetConnection() at System.Net.Mail.SmtpClient.Send(MailMessage message) at _Default.SendEmail(String from, String to, String cc, Int32 port, String subject, String message, String Host) in c:\Vuyiswa\Email_test\Default.aspx.cs:line 53
Thanks
Vuyiswa Maseko,
Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers."
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.somee.com
http://www.vuyiswamaseko.tiyaneProperties.co.za
vuyiswa@its.co.za
http://www.itsabacus.co.za/itsabacus/
|
|
|
|
|
Sounds like your mail server needs configuring.
Christian Graus
Driven to the arms of OSX by Vista.
"! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums.
I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp
|
|
|
|
|
Am Currently using my companies mail server to test. and doing Configuration to suite me will not be a good idea. can i use my Dev machine to test this. i have enabled relying on my System and i see there is my IP.
Thanks
Vuyiswa Maseko,
Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers."
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.somee.com
http://www.vuyiswamaseko.tiyaneProperties.co.za
vuyiswa@its.co.za
http://www.itsabacus.co.za/itsabacus/
|
|
|
|
|
Why not use your own mail server, from your ISP, to test ? Or just tell your boss, I need a proper mail server to test this code.
Christian Graus
Driven to the arms of OSX by Vista.
"! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums.
I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp
|
|
|
|
|
Good Morning Christian
i came across this code
protected void Button1_Click(object sender, EventArgs e)
{
MailMessage mm = new MailMessage();
SmtpClient smtp = new SmtpClient();
mm.From = new MailAddress("Vuyiswa@its.co.za");
mm.To.Add(new MailAddress("Vuyiswa@its.co.za"));
mm.To.Add(new MailAddress("RDG@its.co.za"));
mm.Subject = "Hello";
mm.Body = "<p>This is the E-mail Test for !Booking System</p>";
mm.IsBodyHtml = true;
smtp.Host = "smtp.gmail.com";
smtp.EnableSsl = true;
System.Net.NetworkCredential NetworkCred = new System.Net.NetworkCredential();
NetworkCred.UserName = "vuyiswamb@gmail.com";
NetworkCred.Password = "secret";
smtp.UseDefaultCredentials = true;
smtp.Credentials = NetworkCred;
smtp.Port = 587;
smtp.Send(mm);
}
This code works in Gmail, i will contact the Server Administrator to tell me exactly what port and credetials do i need to use, because i get Port errors.
Thanks for your help
Vuyiswa Maseko,
Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers."
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.somee.com
http://www.vuyiswamaseko.tiyaneProperties.co.za
vuyiswa@its.co.za
http://www.itsabacus.co.za/itsabacus/
|
|
|
|
|
Hi I am populating a dropdownlist using javascript.My code is given below.the problem is that my code works properly in Mozila,Opera.but fails to work in IE.
function popDDL()
{
var ddl=document.getElementById('<%= DropDownList1.ClientID%>');
for(var i=0;i<10;i++)
{
ddl.options[ddl.options.length]=new Option("item"+i,"item"+i);
}
}
It says object doesn't support this property or method
CC26
modified on Friday, June 19, 2009 5:31 AM
|
|
|
|
|
Hi
I have just copy and paste your function in my end and it works perfectly fine.
I think problem is somewhere else.Which version of IE you are using?
himanshu
|
|
|
|
|
thank u himangshu 4 ur reply.but i've solved the problem in other way.
CC26
|
|
|
|
|
I have checklistbox for all types of sub-categories
But I want to seprate sub-categories as per the category in checklistbox.
how can i do this?
modified on Friday, June 19, 2009 5:10 AM
modified on Friday, June 19, 2009 6:10 AM
|
|
|
|
|
TREEVIEW!
In Word you can only store 2 bytes. That is why I use Writer.
|
|
|
|
|
thanx
but can u explain me more
|
|
|
|
|
|
hi sir
how can we bind a template field with another template field value.
sir i mean to say actually my detail column of gridview contain expand/collpse sign.it should be visible when my status column contain value "S" and "A" and for remaining like "No Change" and "New Edition" there should not be expand/collapse sign .
please help me
|
|
|
|
|
Your best way of doing this is to make your databound value be passed into a code behind method, which would then parse it and return the result to show or hide the sign.
Christian Graus
Driven to the arms of OSX by Vista.
"! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums.
I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp
|
|
|
|
|
what is win form user control
|
|
|
|
|
Wrong forum
Anyways, here[^] are the definitions.
जय हिंद
|
|
|
|
|
This is what my firend Google told me
Results 1 - 10 of about 88,400,000 for windows user control[^]. (0.17 seconds)
Manas Bhardwaj
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
Please read the post on how to ask intelligent questions before asking anything here again.
Also, please learn to use some basic research tools.
Christian Graus
Driven to the arms of OSX by Vista.
"! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums.
I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp
|
|
|
|
|
Hi sir,
I have created dynamic imagebuttons. In that postbackurl was not working. So i wrote addhandler. I want to open selected image in new window. How to call the selected image id or get the imageurl in img_Click event..?
Dim tRow5 As New HtmlTableRow()
tblParticulars.Rows.Add(tRow5)
tCell = New HtmlTableCell()
tCell.Align = "Left"
tCell.Width = 300
Dim Img As New ImageButton
Img.ID = "AdvImg" & cnt
Txt1 = Ds1.Tables(0).Rows(i).Item("AdvImg")
Img.ImageUrl = "~/Photos/" & Txt1
Img.Height = "70"
Img.Width = "60"
AddHandler Img.Click, AddressOf Me.Img_Click
tCell.Controls.Add(Img)
tRow5.Cells.Add(tCell)
Private Sub img_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs)
End Sub
|
|
|
|
|
you have to give events like :(in C#)
Img.Click += new EventHandler(Imgbtn_Click);
This will fire the event:
protected void Imgbtn_Click(object sender, EventArgs e)
{
//your code here
}
Padmanabhan
|
|
|
|
|
Sir,
i also did the same thing using foll vb code
AddHandler Img.Click, AddressOf Me.Img_Click
i want to know how to get imageurl or the path of the image so that i can open it in new window when i click the image button in foll function.
protected void Imgbtn_Click(object sender, EventArgs e)
{
//code
}
|
|
|
|
|
hi sir
how can i got src of htmllink (which is in template field of gridview) on code behind.
thank u sir
but i put it Rowdatabound and there is no neweditindex.please suggest what can be next.
modified on Friday, June 19, 2009 2:40 AM
|
|
|
|
|
//write the below code in any one of the events.I prefer RowEditing.
string link = ((TextBox)GridView.Rows[e.NewEditIndex].FindControl("htmllink ")).Text;
Padmanabhan
|
|
|
|