Results 1 to 12 of 12

Thread: [2005] Email

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2008
    Posts
    1,754

    [2005] Email

    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

  2. #2
    Hyperactive Member cameron2's Avatar
    Join Date
    Mar 2008
    Location
    Australia
    Posts
    401

    Re: [2005] Email

    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.

  3. #3
    Hyperactive Member cameron2's Avatar
    Join Date
    Mar 2008
    Location
    Australia
    Posts
    401

    Re: [2005] Email

    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

  4. #4
    Fanatic Member
    Join Date
    Feb 2006
    Posts
    607

    Re: [2005] Email

    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.

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2008
    Posts
    1,754

    Re: [2005] Email

    Quote Originally Posted by masfenix
    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.

    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.

  6. #6
    Fanatic Member
    Join Date
    Feb 2006
    Posts
    607

    Re: [2005] 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:
    1. using System;
    2. using System.Data;
    3. using System.Configuration;
    4. using System.Collections;
    5. using System.Web;
    6. using System.Web.Security;
    7. using System.Web.UI;
    8. using System.Web.UI.WebControls;
    9. using System.Web.UI.WebControls.WebParts;
    10. using System.Web.UI.HtmlControls;
    11. using System.Net.Mail;
    12. using System.Net;
    13.  
    14. public partial class sendmail : System.Web.UI.Page
    15. {
    16.     protected void Page_Load(object sender, EventArgs e)
    17.     {
    18.         SmtpClient smtpClient = new SmtpClient();
    19.         MailMessage message = new MailMessage();
    20.  
    21.         try
    22.         {
    23.             MailAddress fromAddress = new MailAddress("[email protected]", "Softsys-Test");
    24.  
    25.             smtpClient.Host = "72.18.138.246"; //or mail.domain-name.com
    26.  
    27.             //Default port will be 25
    28.             smtpClient.Port = 25;
    29.  
    30.             NetworkCredential info = new NetworkCredential("[email protected]", "***");  //"my login name is my email itself, and password.
    31.             smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
    32.             smtpClient.UseDefaultCredentials = false;
    33.             smtpClient.Credentials = info;
    34.  
    35.             //From address will be given as a MailAddress Object
    36.             message.From = fromAddress;
    37.  
    38.             // To address collection of MailAddress
    39.             message.To.Add("[email protected]");
    40.             message.Subject = "Test-Subject";
    41.  
    42.             //Body can be Html or text format
    43.             //Specify true if it  is html message
    44.             message.IsBodyHtml = false;
    45.  
    46.             // Message body content
    47.             message.Body = "Test Body";
    48.  
    49.             // Send SMTP mail
    50.             smtpClient.Send(message);
    51.  
    52.             Response.Write("Mail sent successfully :-)");
    53.  
    54.         }
    55.         catch (Exception ex)
    56.         {
    57.             Response.Write("Oops! Error encountered. " + ex.Message.ToString());
    58.         }
    59.     }
    60. }

  7. #7
    Hyperactive Member cameron2's Avatar
    Join Date
    Mar 2008
    Location
    Australia
    Posts
    401

    Re: [2005] Email

    Yes that code was straight off the top of my head i am still looking for my e-mail application that worked.

  8. #8

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2008
    Posts
    1,754

    Re: [2005] Email

    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.

  9. #9
    Frenzied Member stimbo's Avatar
    Join Date
    Jun 2006
    Location
    UK
    Posts
    1,739

    Re: [2005] Email

    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
    Stim

    Free VB.NET Book Chapter
    Visual Basic 2005 Cookbook Sample Chapter

  10. #10
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [2005] Email

    noahssite, ASP.NET questions - ASP.NET Forum. You'll have a better chance of getting asp.net related answers there.

  11. #11

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2008
    Posts
    1,754

    Re: [2005] Email

    Only have of it got converted there was an error with the code converter site

  12. #12
    Frenzied Member stimbo's Avatar
    Join Date
    Jun 2006
    Location
    UK
    Posts
    1,739

    Re: [2005] Email

    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:
    1. SmtpClient smtpClient = new SmtpClient();
    2. MailMessage message = new MailMessage();

    to:
    vb Code:
    1. Dim smtpClient As New smtpClient
    2. 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.
    Stim

    Free VB.NET Book Chapter
    Visual Basic 2005 Cookbook Sample Chapter

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width