Click here to Skip to main content
14,668,708 members
Rate this:
Please Sign up or sign in to vote.
See more:
i have the following code,i'm trying to send an email from my windows application but it's not working... any help ? note that i'm using and i'm not getting any errors.. i'm just not receiving any emails !
 Private Sub senemail()
    'create the mail message
    Dim mail As New MailMessage()

    'set the addresses
    mail.From = New MailAddress("")

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

    'send the message
    Dim smtp As New SmtpClient("")
End Sub
Updated 28-Apr-16 20:14pm
[no name] 9-Sep-13 10:27am
Do you actually have an email server setup and running on the computer that you are running this code on?
Joezer BH 9-Sep-13 10:29am

Rate this:
Please Sign up or sign in to vote.

Solution 1

This is very unlikely that you have an SMTP server up and running on this address, which is local. You need to use some external server; and it also very likely that you will need to be registered with that server and use authentication.

Espen Harlinn 10-Sep-13 5:46am
True, unless he installed one for development purposes ...
Sergey Alexandrovich Kryukov 10-Sep-13 10:28am
Exactly. But in that case it would probably work somehow... :-)
Thank you, Espen.
Rate this:
Please Sign up or sign in to vote.

Solution 3

Dim mail As New MailMessage()
        Dim SmtpServer As New SmtpClient("")
        mail.From = New MailAddress(txtid.Text)
        mail.[To].Add("Email Id to")
        mail.Subject = txtsub.Text
        mail.Body = txtmess.Text
        mail.Attachments.Add(New Attachment(OpenFileDialog1.FileName))
        SmtpServer.Port = 587
        SmtpServer.Credentials = New System.Net.NetworkCredential(txtid.Text, txtpass.Text)
        SmtpServer.EnableSsl = True
        mail.From = New MailAddress(txtid.Text)
        MsgBox("E-mail Has Been Send Successfully !")

Its very simple to send email in please check this code or use directly.
If you are send attachment then use the openfiledialogbox control.
Jocelyne El Khoury 13-Sep-13 8:50am
i'm getting failure sending email on this step : SmtpServer.Send(mail)
Rate this:
Please Sign up or sign in to vote.

Solution 2

Have a look at Sending an Email in C# with or without attachments: generic routine.[^]

Best regards
Espen Harlinn

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100