send email using vb.net

Please support our VB.NET advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Apr 2008
Posts: 54
Reputation: Pgmer is an unknown quantity at this point 
Solved Threads: 5
Pgmer Pgmer is offline Offline
Junior Poster in Training

send email using vb.net

 
0
  #1
Aug 27th, 2008
Hi all
in my appliction i want to send the document through mail i.e: outlook
here is my code

Dim myWS As Object
Dim RegKey As String
Dim Key As String
Key = "HKEY_LOCAL_MACHINE\SOFTWARE\Clients\Mail\"
'access Windows scripting
myWS = CreateObject("WScript.Shell")
'read key from registry
RegKey = myWS.RegRead(Key)
If RegKey = "Microsoft Outlook" Then


Dim mailString As String = "mailto:" & "?subject= &body="
Process.Start(mailString)
Dim aFile As String = attachfile
Dim Ret As IntPtr
While Ret = 0
Application.DoEvents()
Ret = FindWindow(vbNullString, " ")
End While
SendKeys.Send("%if" & attachfile & "{ENTER}")
but it is not attaching the file just it opens the outlook
can anybady tell me where im my code goes wrong?
Last edited by Pgmer; Aug 27th, 2008 at 3:36 am.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 113
Reputation: scrypt3r is an unknown quantity at this point 
Solved Threads: 2
scrypt3r's Avatar
scrypt3r scrypt3r is offline Offline
Junior Poster

Re: send email using vb.net

 
0
  #2
Aug 27th, 2008
Yes you can, in fact, haz cheezburgerz
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 126
Reputation: laghaterohan is an unknown quantity at this point 
Solved Threads: 1
laghaterohan laghaterohan is offline Offline
Junior Poster

Re: send email using vb.net

 
0
  #3
Aug 28th, 2008
hey the code which u have posted works for all ? i mean to ask if i copy this code in my application (VB.NET 2005) will this work ? ie..atleast ms outlook window will open ?
and one more thing, RegKey...from where u got it ? or is it common to all ? am a raw fresher so need help kindly reply....thanks a lot in advance

Originally Posted by Pgmer View Post
Hi all
in my appliction i want to send the document through mail i.e: outlook
here is my code

Dim myWS As Object
Dim RegKey As String
Dim Key As String
Key = "HKEY_LOCAL_MACHINE\SOFTWARE\Clients\Mail\"
'access Windows scripting
myWS = CreateObject("WScript.Shell")
'read key from registry
RegKey = myWS.RegRead(Key)
If RegKey = "Microsoft Outlook" Then


Dim mailString As String = "mailto:" & "?subject= &body="
Process.Start(mailString)
Dim aFile As String = attachfile
Dim Ret As IntPtr
While Ret = 0
Application.DoEvents()
Ret = FindWindow(vbNullString, " ")
End While
SendKeys.Send("%if" & attachfile & "{ENTER}")
but it is not attaching the file just it opens the outlook
can anybady tell me where im my code goes wrong?
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 3
Reputation: johnnykenshien is an unknown quantity at this point 
Solved Threads: 1
johnnykenshien johnnykenshien is offline Offline
Newbie Poster

Re: send email using vb.net

 
0
  #4
Aug 28th, 2008
Hello friend try this in vb.net;

  1. Imports System.Web.mail
  2.  
  3. Public Class Form1
  4. Inherits System.Windows.Forms.Form
  5. ' Variable which will send the mail
  6. Dim obj As System.Web.Mail.SmtpMail
  7.  
  8. 'Variable to store the attachments
  9. Dim Attachment As System.Web.Mail.MailAttachment
  10.  
  11. 'Variable to create the message to send
  12. Dim Mailmsg As New System.Web.Mail.MailMessage
  13.  
  14. Private Sub BtnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnAdd.Click
  15. 'Show open dialogue box to select the files to attach
  16. Dim Counter As Integer
  17. OFD.CheckFileExists = True
  18. OFD.Title = "Select file(s) to attach"
  19. OFD.ShowDialog()
  20.  
  21. For Counter = 0 To UBound(OFD.FileNames)
  22. lstAttachment.Items.Add(OFD.FileNames(Counter))
  23. Next
  24. End Sub
  25.  
  26. Private Sub BtnRemove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnRemove.Click
  27. 'Remove the attachments
  28. If lstAttachment.SelectedIndex > -1 Then
  29. lstAttachment.Items.RemoveAt(lstAttachment.SelectedIndex)
  30. End If
  31. End Sub
  32.  
  33. Private Sub btnSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSend.Click
  34. Dim Counter As Integer
  35.  
  36. Try
  37. 'Validate the data
  38. If txtSMTPServer.Text = "" Then
  39. MsgBox("Enter the SMTP server info ...!!!", MsgBoxStyle.Information, "Send Email")
  40. Exit Sub
  41. End If
  42.  
  43. If txtFrom.Text = "" Then
  44. MsgBox("Enter the From email address ...!!!", MsgBoxStyle.Information, "Send Email")
  45. Exit Sub
  46. End If
  47.  
  48. If txtTo.Text = "" Then
  49. MsgBox("Enter the Recipient email address ...!!!", MsgBoxStyle.Information, "Send Email")
  50. Exit Sub
  51. End If
  52.  
  53. If txtSubject.Text = "" Then
  54. MsgBox("Enter the Email subject ...!!!", MsgBoxStyle.Information, "Send Email")
  55. Exit Sub
  56. End If
  57.  
  58. 'Set the properties
  59. 'Assign the SMTP server
  60. obj.SmtpServer = txtSMTPServer.Text
  61. 'Multiple recepients can be specified using ; as the delimeter
  62. 'Address of the recipient
  63. Mailmsg.To = txtTo.Text
  64.  
  65.  
  66. 'Your From Address
  67. 'You can also use a custom header Reply-To for a different replyto address
  68. Mailmsg.From = "\" & txtFromDisplayName.Text & "\ <" & txtFrom.Text & ">"
  69.  
  70.  
  71. 'Specify the body format
  72. If chkFormat.Checked = True Then
  73. Mailmsg.BodyFormat = MailFormat.Html 'Send the mail in HTML Format
  74. Else
  75. Mailmsg.BodyFormat = MailFormat.Text
  76. End If
  77.  
  78. 'If you want you can add a reply to header
  79. 'Mailmsg.Headers.Add("Reply-To", "Manoj@geinetech.net")
  80. 'custom headersare added like this
  81. 'Mailmsg.Headers.Add("Manoj", "TestHeader")
  82.  
  83. 'Mail Subject
  84. Mailmsg.Subject = txtSubject.Text
  85.  
  86. 'Attach the files one by one
  87. For Counter = 0 To lstAttachment.Items.Count - 1
  88. Attachment = New MailAttachment(lstAttachment.Items(Counter))
  89. 'Add it to the mail message
  90. Mailmsg.Attachments.Add(Attachment)
  91. Next
  92.  
  93. 'Mail Body
  94. Mailmsg.Body = txtMessage.Text
  95. 'Call the send method to send the mail
  96. obj.Send(Mailmsg)
  97. MsgBox("Send Complete!")
  98. Catch ex As Exception
  99. MsgBox(ex.Message)
  100. End Try
  101.  
  102. End Sub
  103.  
  104. End Class
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 126
Reputation: laghaterohan is an unknown quantity at this point 
Solved Threads: 1
laghaterohan laghaterohan is offline Offline
Junior Poster

Re: send email using vb.net

 
0
  #5
Aug 28th, 2008
thanks... hope it works....

cya,
Rohan
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 54
Reputation: Pgmer is an unknown quantity at this point 
Solved Threads: 5
Pgmer Pgmer is offline Offline
Junior Poster in Training

Re: send email using vb.net

 
0
  #6
Aug 28th, 2008
Thanks
ur code may work but im interfacing outlook in my appliction. i just want to attach the file with outlook.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 54
Reputation: Pgmer is an unknown quantity at this point 
Solved Threads: 5
Pgmer Pgmer is offline Offline
Junior Poster in Training

Re: send email using vb.net

 
0
  #7
Sep 2nd, 2008
Hi laghaterohan
sory for late reply.
yes it works for all u need to have outlook istalled iin ur machine
basically im checking for the windows registry key, that method vill give u the default mail client once u get it vill open the outlook and attach the file.
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 126
Reputation: laghaterohan is an unknown quantity at this point 
Solved Threads: 1
laghaterohan laghaterohan is offline Offline
Junior Poster

Re: send email using vb.net

 
0
  #8
Sep 2nd, 2008
Originally Posted by Pgmer View Post
Hi laghaterohan
sory for late reply.
yes it works for all u need to have outlook istalled iin ur machine
basically im checking for the windows registry key, that method vill give u the default mail client once u get it vill open the outlook and attach the file.
okie....so from where can i get windows registy key ? btw, the above code in vb.net is also working properly or not ??? i am aksing u this because so that i can directly use it...'coz i dont want to create mess as my application already has too much of coding.......
clarify
Last edited by laghaterohan; Sep 2nd, 2008 at 7:48 am.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 15
Reputation: gomathinayagam is an unknown quantity at this point 
Solved Threads: 1
gomathinayagam gomathinayagam is offline Offline
Newbie Poster

Re: send email using vb.net

 
0
  #9
Dec 13th, 2008
Following Coding Run successfully. Any Body want send a mail Via VB.net. You can use this code.


Send Email with Gmail

This sample base on vb.net 2005.

There are two step to create this.

1. You must insert mailSettings tag in app.config for window application or insert in web.config for web application.

2. Use System.Net.Mail namespace.

Sample Code for window application.
1. Insert this tag in app.config (Config Google SMTP).

<system.net >
<mailSettings >
<smtp from ="Test@Test">
<network host ="smtp.gmail.com" port ="587" password ="your Password" userName ="Your Mail Id"/>
</smtp>
</mailSettings>
</system.net>


2. Use System.Net.Mail namespace.


Imports System.Net.Mail




Dim client As New SmtpClient()

Dim sendTo As New MailAddress("sendToAccount@gmail.com")
Dim from As MailAddress = New MailAddress("from@address.com")
Dim message As New MailMessage(from, sendTo)


message.IsBodyHtml = True
message.Subject = "HI"
message.Body = "Type Your Msg.!!"
'multipleattach()
' Use the same account in app.config to authenticate.
System.Net.NetworkCredential("yourAccount@gmail.com", "YourPassword")


client.Host = "smtp.gmail.com"
client.UseDefaultCredentials = False
client.Credentials = basicAuthenticationInfo
client.EnableSsl = True

Try

client.Send(message)
MsgBox("SUCCESS")

Catch ex As Exception

MsgBox("SEND FAIL")
End Try

All The Best
Regard,
A.Gomathinayagam
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 54
Reputation: Pgmer is an unknown quantity at this point 
Solved Threads: 5
Pgmer Pgmer is offline Offline
Junior Poster in Training

Re: send email using vb.net

 
0
  #10
Dec 13th, 2008
Yes it wil work
just copy and paste the code and run..
if not works plz let me know.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC