Results 1 to 11 of 11

Thread: [2008] Send an email

  1. #1

    Thread Starter
    Lively Member Colin Dias's Avatar
    Join Date
    Jan 2008
    Posts
    99

    [2008] Send an email

    How do i send an email which extracts the email address from a textbox and sends the login details from the database.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2008] Send an email

    This is a common question and, as such, has been answered many times. Raed the MSDN documentation for the System.Net.Mail.MailMessage class for a code example or search the forum. The values that you assign to the properties of the MailMessage, like To and Body, can come from wherever you like.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Lively Member Colin Dias's Avatar
    Join Date
    Jan 2008
    Posts
    99

    Re: [2008] Send an email

    I couldnt find the documentation you mentioned. could you please direct me to the site.

  4. #4
    Fanatic Member
    Join Date
    Feb 2007
    Location
    Eindhoven
    Posts
    828

    Re: [2008] Send an email


  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2008] Send an email

    What is up with all these people who "can't find" a Help menu? Open Visual Studio, select Help -> Index from the main menu and type mailmessage into the box. It's not rocket science. It's not even programming. It's just using a computer.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    Lively Member Colin Dias's Avatar
    Join Date
    Jan 2008
    Posts
    99

    Re: [2008] Send an email

    sorry but im new to programming. I just cant figure out how to send the email in VB.net

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2008] Send an email

    Being new to programming is no reason to not be able to find a topic in a Help file. Any computer user should be able to do that. That said, the MailMessage documentation has code examples in C#, C++ and J# but no VB. Here's the output from Instant VB when converting the C# example:
    vb.net Code:
    1. Public Shared Sub CreateMessageWithAttachment(ByVal server As String)
    2.             ' Specify the file to be attached and sent.
    3.             ' This example assumes that a file named Data.xls exists in the
    4.             ' current working directory.
    5.             Dim file As String = "data.xls"
    6.             ' Create a message and set up the recipients.
    7.             Dim message As MailMessage = New MailMessage("[email protected]", "[email protected]", "Quarterly data report.", "See the attached spreadsheet.")
    8.  
    9.             ' Create  the file attachment for this e-mail message.
    10.             Dim data As Attachment = New Attachment(file, MediaTypeNames.Application.Octet)
    11.             ' Add time stamp information for the file.
    12.             Dim disposition As ContentDisposition = data.ContentDisposition
    13.             disposition.CreationDate = System.IO.File.GetCreationTime(file)
    14.             disposition.ModificationDate = System.IO.File.GetLastWriteTime(file)
    15.             disposition.ReadDate = System.IO.File.GetLastAccessTime(file)
    16.             ' Add the file attachment to this e-mail message.
    17.             message.Attachments.Add(data)
    18.             'Send the message.
    19.             Dim client As SmtpClient = New SmtpClient(server)
    20.             ' Add credentials if the SMTP server requires them.
    21.             client.Credentials = CredentialCache.DefaultNetworkCredentials
    22.             client.Send(message)
    23.             ' Display the values in the ContentDisposition for the attachment.
    24.             Dim cd As ContentDisposition = data.ContentDisposition
    25.             Console.WriteLine("Content disposition")
    26.             Console.WriteLine(cd.ToString())
    27.             Console.WriteLine("File {0}", cd.FileName)
    28.             Console.WriteLine("Size {0}", cd.Size)
    29.             Console.WriteLine("Creation {0}", cd.CreationDate)
    30.             Console.WriteLine("Modification {0}", cd.ModificationDate)
    31.             Console.WriteLine("Read {0}", cd.ReadDate)
    32.             Console.WriteLine("Inline {0}", cd.Inline)
    33.             Console.WriteLine("Parameters: {0}", cd.Parameters.Count)
    34.             For Each d As DictionaryEntry In cd.Parameters
    35.                 Console.WriteLine("{0} = {1}", d.Key, d.Value)
    36.             Next d
    37.             data.Dispose()
    38.         End Sub
    Even with that code, you should still READ the entire Help topic and also follow any relevant links, including those to the members for the MailMessage class and also the related class used in that code, like Attachment and SmtpClient.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  8. #8
    Frenzied Member
    Join Date
    Jan 2008
    Posts
    1,754

    Re: [2008] Send an email

    that code was for VB?

  9. #9
    Frenzied Member
    Join Date
    Jan 2008
    Posts
    1,754

    Re: [2008] Send an email

    nvm srry i didnt really see

  10. #10

    Thread Starter
    Lively Member Colin Dias's Avatar
    Join Date
    Jan 2008
    Posts
    99

    Re: [2008] Send an email

    Should this code be used in the button click event??

  11. #11
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2008] Send an email

    Quote Originally Posted by Colin Dias
    Should this code be used in the button click event??
    You tell me. Do you want to send a message when a Button is clicked? If you do then you'd put the code in the Button's Click event handler. If you don't then you wouldn't.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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