Solved

What is the best way to send an email with .net 2.0?

Posted on 2006-11-20
3
250 Views
Last Modified: 2010-04-23
I am rebuilding a project that I had made a few years ago and would like to start using .net 2.0.  What object would be the best to use?  On the old project I used CDO.Message.

Thanks
0
Comment
Question by:GabicusC
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 3

Assisted Solution

by:schott19
schott19 earned 170 total points
ID: 17982071
Hi there,

this is a great site that i used when i was asking the same question..

http://www.systemnetmail.com/

gives you basic information as well as more complex stuff so will cover all you need to know.

A simple example from the site to send an email is:

 'create the mail message
Dim mail As New MailMessage()

'set the addresses
mail.From = New MailAddress("me@mycompany.com")
mail.To.Add("you@yourcompany.com")

'set the content
mail.Subject = "This is an email"
mail.Body = "this is a sample body"

'send the message
Dim smtp As New SmtpClient("127.0.0.1")
smtp.Send(mail)


Regards

0
 
LVL 14

Assisted Solution

by:ptakja
ptakja earned 160 total points
ID: 17982319
0
 
LVL 63

Accepted Solution

by:
Fernando Soto earned 170 total points
ID: 17982414
Hi GabicusC;

Here is some sample code to show how to use Net.Mail

Note that this line needs to be changed in the sample code below to the smtp server you are using:

        mailSender = New SmtpClient("Your smtp-server.com", 25)


Imports System.Net.Mail

    Private Sub SendEmail(ByVal sender As String, _
        ByVal recipient As String, ByVal subject As String, _
        ByVal body As String, Optional ByVal attachmentString As String = "")

        Dim fromAddress As New MailAddress(sender)
        Dim toAddress As New MailAddress(recipient)
        Dim message As New MailMessage(fromAddress, toAddress)

        Dim mailSender As SmtpClient
        mailSender = New SmtpClient("Your smtp-server.com", 25)

        message.Bcc.Add(fromAddress)
        message.Subject = subject
        message.IsBodyHtml = False
        message.Body = body

        If Not attachmentString = "" Then
            Dim msgAttach As New Attachment(attachmentString)
            message.Attachments.Add(msgAttach)
        End If

        Try
            mailSender.Send(message)
        Catch ex As Exception
            MessageBox.Show(ex.Message, "Error Mail Not Sent")
        End Try

    End Sub


    Private Sub Button1_Click(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles Button1.Click

        SendEmail("Fernando-Soto@mydomain.com", "Margarita-Rada@mydomain.com", _
            "This is a test", "This is the Body", "c:\Temp\pp1.pdf")

    End Sub


Fernando
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question