How do i make it so when a button is clicked the text of a textbox is sent as a email to a certain address?????
Don't give links to other threads since none of them explain because i want VISUAL BASIC 2005. Please leave an example...
Thankyou
Printable View
How do i make it so when a button is clicked the text of a textbox is sent as a email to a certain address?????
Don't give links to other threads since none of them explain because i want VISUAL BASIC 2005. Please leave an example...
Thankyou
First of all you need an smtp server to work on. You can't just send an e-mail from nothing.
I suggest that you make an e-mail account on bluebottle.com or any e-mail that has POP3/smtp (not hotmail) and find out their smtp.
I have some code that can send an e-mail i just have to find it.
Cameron.
Here's the code:
1. add about 4 textboxes to your form.
2. add a button
Dim mail as new system.web.mail.mailmessage
"Button click sub here"
SmtpMail.SmtpServer = "Yoursmtpserver, Password"
mail = new MailMessage()
mail.To = Textbox1.text
mail.From = Textbox2.Text
mail.Subject = Textbox3.text
mail.Body = textbox4.text
SmtpMail.Send(mail)
End sub()
This code should work if not post the error and i will try and fix it.
Cameron
Sorry to say but camerons code will most likely not work. You'll have to use SMTP. Your ISP provides a SMTP for you to use.
Alternatively you can signup for google's gmail, and use their SMTP server.
Most liekly you'll need to login using credentials.
Quote:
Originally Posted by masfenix
I dont quite understand.... So the reason i wanted to know how to do email is because im making a asp.net website and im making it in visual basic so i want to make a contact us page. I need to know how to do email.
Most SMTP servers require you to login.
edit: I know this is in C#.Net but it can be converted VERY EASILY.. all it does is use the .net Email classes
vb Code:
using System; using System.Data; using System.Configuration; using System.Collections; 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.Net.Mail; using System.Net; public partial class sendmail : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { SmtpClient smtpClient = new SmtpClient(); MailMessage message = new MailMessage(); try { MailAddress fromAddress = new MailAddress("[email protected]", "Softsys-Test"); smtpClient.Host = "72.18.138.246"; //or mail.domain-name.com //Default port will be 25 smtpClient.Port = 25; NetworkCredential info = new NetworkCredential("[email protected]", "***"); //"my login name is my email itself, and password. smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network; smtpClient.UseDefaultCredentials = false; smtpClient.Credentials = info; //From address will be given as a MailAddress Object message.From = fromAddress; // To address collection of MailAddress message.To.Add("[email protected]"); message.Subject = "Test-Subject"; //Body can be Html or text format //Specify true if it is html message message.IsBodyHtml = false; // Message body content message.Body = "Test Body"; // Send SMTP mail smtpClient.Send(message); Response.Write("Mail sent successfully :-)"); } catch (Exception ex) { Response.Write("Oops! Error encountered. " + ex.Message.ToString()); } } }
Yes that code was straight off the top of my head i am still looking for my e-mail application that worked.
ok so now i need to convert it....just wondering can VB 2005 use tags? to insert another code into a visual basic code? Ive never done that before since i only know visual basic.
there are loads of websites that do vb to c# .net conversion and vice versa.
Just copy/paste that code in and it will change it for you.
Code converter
noahssite, ASP.NET questions - ASP.NET Forum. You'll have a better chance of getting asp.net related answers there.
Only have of it got converted there was an error with the code converter site
There's really not much difference in the code compared to the vb version
Instead of 'Using' it's 'Imports' in VB
Variable delcarations are simply changed from:
vb Code:
SmtpClient smtpClient = new SmtpClient(); MailMessage message = new MailMessage();
to:
vb Code:
Dim smtpClient As New smtpClient Dim message As New MailMessage
Just do the same thing for the other variable declarations and take the ; character off the end of the other lines and that's it really. A little effort working it out will have it done in minutes.