locked
I am trying to email using the VB.NET RRS feed

  • 问题

  • Please some one help me with code for emailing using VB.NET
    2011年5月2日 14:53

答案

  • Hi Shankar Singh,

    I am emailing you the code to send email using the windows application in VB.NET just paste the following code in VB.NET file and call this method when you want to send an email by replacing the the required values

    Public Sub Emails()
    Try
    	Dim msg As New System.Net.Mail.MailMessage()
    	msg.[To].Add("Recipent Email Address")
    	msg.Subject = "Something"
    	msg.Body = Textbox1.Text
    	msg.IsBodyHtml = False
    	Dim SMPclint As New SmtpClient()
    	SMPclint.Host = "smtp.gmail.com"
    	SMPclint.EnableSsl = True
    	Dim NetCry As New NetworkCredential()
    	NetCry.UserName = "Senders Email Address"
    	NetCry.Password = "Senders Email Login Password"
    	SMPclint.UseDefaultCredentials = True
    	SMPclint.Credentials = NetCry
    	Dim fromMailAddr As New MailAddress("Display Email To Recipient", "Display Name To Recipient")
    	msg.From = fromMailAddr
    	SMPclint.Port = 587
    	SMPclint.Send(msg)
    	MessageBox.Show("Message Sent")
    Catch ex As Exception
    	MessageBox.Show(ex.Message)
    End Try
    End Sub
    
    

    Replace the recipient to Email Address, subject and body, here we use Gmail as the SMTP Client you need to use the SMTP address of your email provider in Host property, replace UserName and Password with your login username and password...

    Thanks,


    Roozan Parvez Bharucha MCT, MCITP (SQL Server 2008, Windows 7 Admin), MCTS (SQL Server 2008, Windows 7 Config, .NET Frmwk 3.5, .NET Frmwk 4.0 (Windows)), MCPD Enterprize App (Frmwk 3.5), MCPD Windows (Frmwk 4.0) CEO, RajAryanTech
    2011年5月2日 17:09

全部回复

  • http://www.systemnetmail.com/

    http://intelomkar.wordpress.com/2010/04/09/send-email-using-gmail/

    http://social.msdn.microsoft.com/Forums/en-US/Vsexpressvb/thread/357245ee-fbaf-4ba2-8ba3-fa005655c687/

    Please search before posting. You'd have found many more.


    Thanks

    Social lounge for MSDN forum users :-)
    Living on Earth may be expensive, but did you know that it includes a free trip around the sun? Isn't that worth it?
    2011年5月2日 15:25
  • Hi Shankar Singh,

    I am emailing you the code to send email using the windows application in VB.NET just paste the following code in VB.NET file and call this method when you want to send an email by replacing the the required values

    Public Sub Emails()
    Try
    	Dim msg As New System.Net.Mail.MailMessage()
    	msg.[To].Add("Recipent Email Address")
    	msg.Subject = "Something"
    	msg.Body = Textbox1.Text
    	msg.IsBodyHtml = False
    	Dim SMPclint As New SmtpClient()
    	SMPclint.Host = "smtp.gmail.com"
    	SMPclint.EnableSsl = True
    	Dim NetCry As New NetworkCredential()
    	NetCry.UserName = "Senders Email Address"
    	NetCry.Password = "Senders Email Login Password"
    	SMPclint.UseDefaultCredentials = True
    	SMPclint.Credentials = NetCry
    	Dim fromMailAddr As New MailAddress("Display Email To Recipient", "Display Name To Recipient")
    	msg.From = fromMailAddr
    	SMPclint.Port = 587
    	SMPclint.Send(msg)
    	MessageBox.Show("Message Sent")
    Catch ex As Exception
    	MessageBox.Show(ex.Message)
    End Try
    End Sub
    
    

    Replace the recipient to Email Address, subject and body, here we use Gmail as the SMTP Client you need to use the SMTP address of your email provider in Host property, replace UserName and Password with your login username and password...

    Thanks,


    Roozan Parvez Bharucha MCT, MCITP (SQL Server 2008, Windows 7 Admin), MCTS (SQL Server 2008, Windows 7 Config, .NET Frmwk 3.5, .NET Frmwk 4.0 (Windows)), MCPD Enterprize App (Frmwk 3.5), MCPD Windows (Frmwk 4.0) CEO, RajAryanTech
    2011年5月2日 17:09
  • OK Mr. Omie,

    I am not fake. I am an MCPD 3.5 Enterprize developer and have a valid MCP ID. let the moderators inspect my account sir.

    I dont know why people like you feel jealous about good answers being marked.

    2011年5月3日 5:15
  • OK Mr. Omie,

    I am not fake. I am an MCPD 3.5 Enterprize developer and have a valid MCP ID. let the moderators inspect my account sir.

    I dont know why people like you feel jealous about good answers being marked.

     

    Roozan Bharucha is MCPD 3.5 Enterprize developer too ! isn't it a nice co-incidence :-)

    Thanks for proving my point. This is my last post here. I don't have time for this.


    Thanks

    Social lounge for MSDN forum users :-)
    Living on Earth may be expensive, but did you know that it includes a free trip around the sun? Isn't that worth it?
    2011年5月3日 5:24
  • Shankar,

    if you're really an MCPD, wouldn't you know how to setup a MailMessage and send it? Or atleast find a sample by searching for it. Newbies asks these kind of questions, not MCPD's. This just proves that what you and your co-workers are doing is just a cheap act to gain as much points as possible. This isn't really helping anyone.

    /Calle


    - Still confused, but on a higher level -
    2011年5月5日 20:37
  • WTH ! I don't want fake points. Please Undo that helpful vote :-\
    Thanks

    Social lounge for MSDN forum users :-)
    Living on Earth may be expensive, but did you know that it includes a free trip around the sun? Isn't that worth it?
    2011年5月6日 5:41
  • Mr. Omie,

    We all QUIT MSDN... please pass on the comment to system admin....

    Thanks,


    Roozan Parvez Bharucha MCT, MCITP (SQL Server 2008, Windows 7 Admin), MCTS (SQL Server 2008, Windows 7 Config, .NET Frmwk 3.5, .NET Frmwk 4.0 (Windows)), MCPD Enterprize App (Frmwk 3.5), MCPD Windows (Frmwk 4.0) CEO, RajAryanTech
    2011年5月6日 6:00