Click here to Skip to main content
15,880,427 members
Please Sign up or sign in to vote.
2.54/5 (3 votes)
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 !
VB
 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!

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
 
Share this answer
 
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
VB
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.
 
Share this answer
 
Comments
Jocelyne El Khoury 13-Sep-13 8:50am    
i'm getting failure sending email on this step : SmtpServer.Send(mail)
Have a look at Sending an Email in C# with or without attachments: generic routine.[^]

Best regards
Espen Harlinn
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900