Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I need help generating an email from my vb.net app.

Status
Not open for further replies.

RotorTorque

Programmer
Apr 29, 2007
100
US
Hi all,
I have a VB.Net application that displays an order's information.
If the user chooses they could click a button to generate an email. When this happens the order information will be saved in a pdf file and then emailed.

From my application how can I generate an email that will get mailed via outlook express from our email server with the pdf file as an attachment?

Thanks in advance,
RotorTorque :)
 
The short answer to your question is to use the "System.Net.Mail" namespace (in VS 2005).

If you have VS 2003 then try the "System.Web.Mail" name space.


Senior Software Developer
 
Do you know of any examples on how to use the System.Net.Mail?

Thanks,
RotorTorque
 
From the VS.NET Help... ;o)

-------------------------------------------------
SUMMARY
This article demonstrates how to use System.Web.Mail to send an e-mail message in Visual Basic .NET.
MORE INFORMATION
Start Microsoft Visual Studio .NET. On the File menu, click New and then click Project. Click Visual Basic Projects, click the Console Application template, and then click OK. By default, Module1.vb is created.
Add a reference to System.Web.dll. To do this, follow these steps:
On the Project menu, click Add Reference.
On the .NET tab, locate System.Web.dll, and then click Select.
Click OK in the Add References dialog box to accept your selections. If you receive a prompt to generate wrappers for the libraries you selected, click Yes.
In the code window, replace the whole code with:
Imports System.Web.Mail

Module Module1

Sub Main()

Dim oMsg As MailMessage = New MailMessage()

' TODO: Replace with sender e-mail address.
oMsg.From = "sender@somewhere.com"
' TODO: Replace with recipient e-mail address.
oMsg.To = "recipient@somewhere.com"
oMsg.Subject = "Send using Web Mail"

' SEND IN HTML FORMAT (comment this line to send plain text).
oMsg.BodyFormat = MailFormat.Html

'HTML Body (remove HTML tags for plain text).
oMsg.Body = "<HTML><BODY><B>Hello World!</B></BODY></HTML>"

' ADD AN ATTACHMENT.
' TODO: Replace with path to attachment.
Dim sFile As String = "C:\temp\Hello.txt"
Dim oAttch As MailAttachment = New MailAttachment(sFile, MailEncoding.Base64)

oMsg.Attachments.Add(oAttch)

' TODO: Replace with the name of your remote SMTP server.
SmtpMail.SmtpServer = "MySMTPServer"
SmtpMail.Send(oMsg)

oMsg = Nothing
oAttch = Nothing
End Sub

End Module

Modify code where you see "TODO".
Press F5 to build and run the program.
Verify that the e-mail message has been sent and received.
Keywords: kbhowto KB314201
Technology: kbAudDeveloper kbVBNET2002 kbVBNETSearch kbVBSearch

---------------------------------------------


Senior Software Developer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top