Today I came across someone who was having trouble sending email from their ASP.net webpage, so I decided to create a little example of how to do so.
Step 1:
Before you can use my coding you must add my Send_Mail() method to your page’s behind the scenes class. To do this, right click on your .aspx page in your Solution Explorer, and select “View Code”. Once in this window, scroll to the very body, and right above “End Class“, paste the following:
''' <summary>''' This will allow you to send email in one simple sub call''' </summary>'''<param name="smtp_username">The login for your SMTP server. Ussualy same as your pop3 login</param>'''<param name="smtp_password">The password for your SMTP server, ussualy same as your pop3 password</param>'''<param name="smtp_server">The mail server to send to. Ussualy mail.yourdomain.com</param>'''<param name="smtp_port">The port for your smtp server. More than likely always 25</param>'''<param name="mail_from">Who to send mail from. For alot of servers (including smarter mail) this must be same as smtp_username</param>'''<param name="mail_to">Who we are sending the mail to</param>'''<param name="mail_subject">What your mail subject will be</param>'''<param name="mail_body">What your mail body will be, HTML enabled</param>''' <remarks>created by www.CoderGuru.com</remarks>PublicSub Send_Mail(ByVal smtp_username AsString, ByVal smtp_password AsString, ByVal smtp_server AsString, ByVal smtp_port AsString, ByVal mail_from AsString, ByVal mail_to AsString, ByVal mail_subject AsString, ByVal mail_body AsString)'Dont edit anything below here unless you want BCC, simply uncomment my lineDim mail AsNew System.Net.Mail.MailMessage(mail_from, mail_to)
mail.Subject= mail_subject
mail.IsBodyHtml=True
mail.Body= mail_body
'mail.Bcc.Add("you_get_copy_too@foo.bar") 'Uncomment to add BCC's to this messageDim smtp AsNew System.Net.Mail.SmtpClient(smtp_server, smtp_port)Dim nc AsNew System.Net.NetworkCredential(smtp_username, smtp_password)
smtp.Credentials= nc
smtp.Send(mail)EndSub
Step 2:
Once you have the method loaded, in your send button paste the following and fill in the fields needed:
1
2
3
4
5
6
7
8
9
10
11
12
'Below holds your SMTP login informationDim smtp_username AsString="username here"Dim smtp_password AsString="password here"Dim smtp_server AsString="mail.yourdomain.com"Dim smtp_port AsInteger=25'Will more than likely never changeDim mail_from AsString= smtp_username' For me my login is my email so simply reference that stringDim mail_to AsString="some_Email@somedomain.com"Dim mail_subject AsString="Hello World!"Dim mail_body AsString="look mom, my email holds <b>html</b> =0"
Send_Mail(smtp_password, smtp_password, smtp_server, smtp_port, mail_from, mail_to, mail_subject, mail_body)
Check back soon for a working example in both VB.net and C#
To go along with my “Disabling / switching keys on your keyboard” post, I also was asked how to disable the windows task manager so that potential users could not turn off the computer or close down any running applications. This was a bit tricky, but after some googling, I was able to come across a built in setting for windows that does just this.
By default Windows doesn’t have access to this setting just sitting around for you to turn on and off, but with a little registry modifications, it can easily be done. The key you are looking to modify is inside [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System] and is called [DisableTaskMgr]. If you want your task manager off you simply set the dword Hexadecimal value to to “1″, and to re-enable it, simply clange it back to 0. Note that the first time you do this, you will more than likely have to create both the “System” folder and “DisableTaskMgr” key.
Don’t know how to work with the registry? Don’t worry, no research needed! Below is a zip file containing two different registry (.reg) files that you can download to automatically handle this! All you do is simply run the file and after you confirm you want to execute the file, your task manager will be set to the settings of your choice.
Have you ever wanted to disable certain keys on your keyboard but have no idea how? After hours of searching, I managed to find a simple way to do such a task, and it works like a charm.
Now like most programmers, I figured “Hey I can probably just stop the keys from occurring in Visual Basic by hijacking the keyboard and only passing on the keys I wanted.” Well this did not work as well as I hoped, so I decided I would ask my ultimate source for knowledge, good old Google. After a few hours of searching different senerios, I finally came across just want I wanted! The Windows Server 2003 Resource Kit Tools.
Now the Windows Server 2003 Resource Kit Tools is a extremely large package packed with many different useful tools, but the tool that will come in handy today is called a crafty little application called “Remap” created by Microsoft.
By using remap, you have full access to “Remap” each and every keyboard key to a different key. Now why is this useful? Well it allows us to change the keys users could use to close our application and replace them with “SHIFT”. We went one step futhor and disabled almost any key combination that could be used to do anything we did not want such as ALT+TAB (switch window), CTRL+F2 (close window), ESCAPE (closes flash presentation), and Windows keys. To make it easy, we simply replaced each and every key we did not want with the Shift key, since the Shift key posed us no harm.
Disabling / switching keys on your keyboard
To use remap your keyboard, follow these simple steps: (how-to video at bottom)
Download the Windows Server 2003 Resource Kit Tools from Microsofts website by clicking here.
Once your download is complete, run “rktools.exe” which will install a whole bunch of tools for you to explore.
Goto Start -> Run -> and type “remapkey.exe” inside the open text box. Then press OK
At this point, Remapkey will open up, displaying the window to the left. The top “Base keyboard” is how your keyboard would be by default. The “Remapped keyboard” is how it will be after. Simply drag and drop the keys from your “Base Keyboard” into the possition you want on your Remapped Keyboard. In our example, we dragged “Shift” from the top to the “Esc” key on the bottom.
When you have your keys exactly as you want them, simple click on the first icon below file to save your changes. It will ask you to confirm your changes and a reboot will be required.
Once you have rebooted, your computer will now work as if your keyboard was setup just as you choose. You can go back to this program at any time to change your keyboard back.
Hope this helps some of you out so you don’t have to spend as much time as I did researching how to stop keystrokes from happening =]