How do i send an email which extracts the email address from a textbox and sends the login details from the database.
Printable View
How do i send an email which extracts the email address from a textbox and sends the login details from the database.
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.
I couldnt find the documentation you mentioned. could you please direct me to the site.
link to the System.Net.mail.MailMessage
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.
sorry but im new to programming. I just cant figure out how to send the email in VB.net
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: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.vb.net Code:
Public Shared Sub CreateMessageWithAttachment(ByVal server As String) ' Specify the file to be attached and sent. ' This example assumes that a file named Data.xls exists in the ' current working directory. Dim file As String = "data.xls" ' Create a message and set up the recipients. Dim message As MailMessage = New MailMessage("[email protected]", "[email protected]", "Quarterly data report.", "See the attached spreadsheet.") ' Create the file attachment for this e-mail message. Dim data As Attachment = New Attachment(file, MediaTypeNames.Application.Octet) ' Add time stamp information for the file. Dim disposition As ContentDisposition = data.ContentDisposition disposition.CreationDate = System.IO.File.GetCreationTime(file) disposition.ModificationDate = System.IO.File.GetLastWriteTime(file) disposition.ReadDate = System.IO.File.GetLastAccessTime(file) ' Add the file attachment to this e-mail message. message.Attachments.Add(data) 'Send the message. Dim client As SmtpClient = New SmtpClient(server) ' Add credentials if the SMTP server requires them. client.Credentials = CredentialCache.DefaultNetworkCredentials client.Send(message) ' Display the values in the ContentDisposition for the attachment. Dim cd As ContentDisposition = data.ContentDisposition Console.WriteLine("Content disposition") Console.WriteLine(cd.ToString()) Console.WriteLine("File {0}", cd.FileName) Console.WriteLine("Size {0}", cd.Size) Console.WriteLine("Creation {0}", cd.CreationDate) Console.WriteLine("Modification {0}", cd.ModificationDate) Console.WriteLine("Read {0}", cd.ReadDate) Console.WriteLine("Inline {0}", cd.Inline) Console.WriteLine("Parameters: {0}", cd.Parameters.Count) For Each d As DictionaryEntry In cd.Parameters Console.WriteLine("{0} = {1}", d.Key, d.Value) Next d data.Dispose() End Sub
that code was for VB?
nvm srry i didnt really see
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.Quote:
Originally Posted by Colin Dias