RSS

Monthly Archives: October 2010

how to send email in asp.net with C#


  1. System;
  2. using System.Configuration;
  3. using System.Web;
  4. using System.Web.Security;
  5. using System.Web.UI;
  6. using System.Web.UI.WebControls;
  7. using System.Web.UI.HtmlControls;
  8. using System.Net.Mail;
  9. public partial class _Default : System.Web.UI.Page
  10. {
  11. #region "Send email"
  12. protected void btnSendmail_Click(object sender, EventArgs e)
  13. {
  14. // System.Web.Mail.SmtpMail.SmtpServer is obsolete in 2.0
  15. // System.Net.Mail.SmtpClient is the alternate class for this in 2.0
  16. SmtpClient smtpClient = new SmtpClient();
  17. MailMessage message = new MailMessage();
  18. try
  19. {
  20. MailAddress fromAddress = new MailAddress(txtEmail.Text, txtName.Text);
  21. // You can specify the host name or ipaddress of your server
  22. // Default in IIS will be localhost
  23. smtpClient.Host = "localhost";
  24. //Default port will be 25
  25. smtpClient.Port = 25;
  26. //From address will be given as a MailAddress Object
  27. message.From = fromAddress;
  28. // To address collection of MailAddress
  29. message.To.Add("john_begginer@yahoo.co.in");
  30. message.Subject = "Feedback";
  31. // CC and BCC optional
  32. // MailAddressCollection class is used to send the email to various users
  33. // You can specify Address as new MailAddress("admin1@yoursite.com")
  34. // message.CC.Add("");
  35. // message.CC.Add("");
  36. // You can specify Address directly as string
  37. //message.Bcc.Add(new MailAddress(""));
  38. //message.Bcc.Add(new MailAddress(""));
  39. //Body can be Html or text format
  40. //Specify true if it is html message
  41. message.IsBodyHtml = false;
  42. // Message body content
  43. message.Body = txtMessage.Text;
  44. // Send SMTP mail
  45. smtpClient.Send(message);
  46. lblStatus.Text = "Email successfully sent.";
  47. }
  48. catch (Exception ex)
  49. {
  50. lblStatus.Text = "Send Email Failed.<br>" + ex.Message;
  51. }
  52. }
  53. #endregion
  54. #region "Reset"
  55. protected void btnReset_Click(object sender, EventArgs e)
  56. {
  57. txtName.Text = "";
  58. txtMessage.Text = "";
  59. txtEmail.Text = "";
  60. }
  61. #endregion
  62. }
You need to set Relay IP-Address. (Relay restrictions). Steps: 1. Open IIS applet from the control panel 2. Go to0 Default SMTP Virtual Server 3. Select tab Access + Click on Relay. 4. Add IP of localhost 127.0.0.1 you need to check mail in C:\Inetpub\mailroot\Queue ........... the configuraion for this plz see this link http://www.emailarchitect.net/webapp/smtpcom/developers/smtpservice.asp
 
Leave a comment

Posted by on October 26, 2010 in ASP Dot Net C#

 

encrypt or decrypt password in c# with asp.net


How to encode a password use base64

—————————————————————————————————————-

For Testing Purpose

protected void txtEncode_Click(object sender, EventArgs e)
{
lblEncode.Text= base64Encode(txtEncode.Text);
}

—————————————————————————–

private string base64Encode(string sData)
{
try
{
byte[] encData_byte = new byte[sData.Length];

encData_byte = System.Text.Encoding.UTF8.GetBytes(sData); 

string encodedData = Convert.ToBase64String(encData_byte);

return encodedData;

}
catch(Exception ex)
{
throw new Exception("Error in base64Encode" + ex.Message);
}
}

--------------------------------------------------------------------------

HOW TO DECODE IT after Encode

------------------------------------------------------------------------
For Testing Purpose.

protected void btnDecode_Click(object sender, EventArgs e)
 {
 lblDecode.Text= base64Decode(lblEncode.Text);
 }
-----------------------------------------------------------------

public string base64Decode(string sData)

{

System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding(); 

System.Text.Decoder utf8Decode = encoder.GetDecoder();

byte[] todecode_byte = Convert.FromBase64String(sData);

int charCount = utf8Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length); 

char[] decoded_char = new char[charCount];

utf8Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0); 

string result = new String(decoded_char);

return result;

}


—————————————————————————————–

HOW TO USE:

pass the password at the time of registration process to that function and save it in the database .At the time of login retrive it and decode it and compare with password entered by user,if successful then redirect to another page else will be in correct email or UserID and password.

calling function for encode

—————————————————————————————————-

 

string pwed = base64encode(val); 


calling function for decode

string pwed = base64Decode(val); 

if this Article helpful for you then give comments......
 
Leave a comment

Posted by on October 25, 2010 in ASP Dot Net C#

 

sql TRANSACTION Management


stored procedures that executes multiple stored procedures within it:

ALTER PROCEDURE [dbo].[AssetLibrary_AssetDelete]
(
    @AssetID AS uniqueidentifier
)
AS

SET NOCOUNT ON

SET TRANSACTION ISOLATION LEVEL READ COMMITTED

EXEC AssetLibrary_AssetDeleteAttributes @AssetID
EXEC AssetLibrary_AssetDeleteComponents @AssetID
EXEC AssetLibrary_AssetDeleteAgreements @AssetID
EXEC AssetLibrary_AssetDeleteMaintenance @AssetID

DELETE FROM
    AssetLibrary_Asset
WHERE
    AssetLibrary_Asset.AssetID = @AssetID

RETURN (@@ERROR)
 
Leave a comment

Posted by on October 5, 2010 in SQL Query