Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2006-11-20
3
Medium Priority
?
251 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 680 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 640 total points
ID: 17982319
0
 
LVL 64

Accepted Solution

by:
Fernando Soto earned 680 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

688 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