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 vb.net 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("jocelyne_elkhoury@inmobiles.net")
    mail.To.Add("jocelyne_el_khoury@hotmail.co.uk")

    '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)
End Sub
Posted
Updated 28-Apr-16 20:14pm
Comments
[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
   
5ed!

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.

—SA
   
Comments
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.
—SA
Rate this:
Please Sign up or sign in to vote.

Solution 3

Dim mail As New MailMessage()
        Dim SmtpServer As New SmtpClient("smtp.gmail.com")
        mail.From = New MailAddress(txtid.Text)
        mail.[To].Add("Email Id to send@rediffmail.com")
        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
        SmtpServer.Send(mail)
        mail.From = New MailAddress(txtid.Text)
        MsgBox("E-mail Has Been Send Successfully !")

Its very simple to send email in vb.net please check this code or use directly.
If you are send attachment then use the openfiledialogbox control.
   
Comments
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