| | |
send email using vb.net
Please support our VB.NET advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Apr 2008
Posts: 54
Reputation:
Solved Threads: 5
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?
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.
I dont know about the code youve got there but try
http://www.osix.net/modules/article/?id=377
http://www.jscape.com/articles/ex_se...l_using_vb.txt
http://www.thescarms.com/dotnet/Email.aspx
http://www.osix.net/modules/article/?id=377
http://www.jscape.com/articles/ex_se...l_using_vb.txt
http://www.thescarms.com/dotnet/Email.aspx
Yes you can, in fact, haz cheezburgerz
•
•
Join Date: Aug 2008
Posts: 126
Reputation:
Solved Threads: 1
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
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
•
•
•
•
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?
•
•
Join Date: Aug 2008
Posts: 3
Reputation:
Solved Threads: 1
Hello friend try this in vb.net;
VB.NET Syntax (Toggle Plain Text)
Imports System.Web.mail Public Class Form1 Inherits System.Windows.Forms.Form ' Variable which will send the mail Dim obj As System.Web.Mail.SmtpMail 'Variable to store the attachments Dim Attachment As System.Web.Mail.MailAttachment 'Variable to create the message to send Dim Mailmsg As New System.Web.Mail.MailMessage Private Sub BtnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnAdd.Click 'Show open dialogue box to select the files to attach Dim Counter As Integer OFD.CheckFileExists = True OFD.Title = "Select file(s) to attach" OFD.ShowDialog() For Counter = 0 To UBound(OFD.FileNames) lstAttachment.Items.Add(OFD.FileNames(Counter)) Next End Sub Private Sub BtnRemove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnRemove.Click 'Remove the attachments If lstAttachment.SelectedIndex > -1 Then lstAttachment.Items.RemoveAt(lstAttachment.SelectedIndex) End If End Sub Private Sub btnSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSend.Click Dim Counter As Integer Try 'Validate the data If txtSMTPServer.Text = "" Then MsgBox("Enter the SMTP server info ...!!!", MsgBoxStyle.Information, "Send Email") Exit Sub End If If txtFrom.Text = "" Then MsgBox("Enter the From email address ...!!!", MsgBoxStyle.Information, "Send Email") Exit Sub End If If txtTo.Text = "" Then MsgBox("Enter the Recipient email address ...!!!", MsgBoxStyle.Information, "Send Email") Exit Sub End If If txtSubject.Text = "" Then MsgBox("Enter the Email subject ...!!!", MsgBoxStyle.Information, "Send Email") Exit Sub End If 'Set the properties 'Assign the SMTP server obj.SmtpServer = txtSMTPServer.Text 'Multiple recepients can be specified using ; as the delimeter 'Address of the recipient Mailmsg.To = txtTo.Text 'Your From Address 'You can also use a custom header Reply-To for a different replyto address Mailmsg.From = "\" & txtFromDisplayName.Text & "\ <" & txtFrom.Text & ">" 'Specify the body format If chkFormat.Checked = True Then Mailmsg.BodyFormat = MailFormat.Html 'Send the mail in HTML Format Else Mailmsg.BodyFormat = MailFormat.Text End If 'If you want you can add a reply to header 'Mailmsg.Headers.Add("Reply-To", "Manoj@geinetech.net") 'custom headersare added like this 'Mailmsg.Headers.Add("Manoj", "TestHeader") 'Mail Subject Mailmsg.Subject = txtSubject.Text 'Attach the files one by one For Counter = 0 To lstAttachment.Items.Count - 1 Attachment = New MailAttachment(lstAttachment.Items(Counter)) 'Add it to the mail message Mailmsg.Attachments.Add(Attachment) Next 'Mail Body Mailmsg.Body = txtMessage.Text 'Call the send method to send the mail obj.Send(Mailmsg) MsgBox("Send Complete!") Catch ex As Exception MsgBox(ex.Message) End Try End Sub End Class
•
•
Join Date: Aug 2008
Posts: 126
Reputation:
Solved Threads: 1
•
•
•
•
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.
clarify
Last edited by laghaterohan; Sep 2nd, 2008 at 7:48 am.
•
•
Join Date: Nov 2008
Posts: 15
Reputation:
Solved Threads: 1
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
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
A.Gomathinayagam
![]() |
Similar Threads
- How to send am Email using c# ? (C#)
- Send an Email in PHP (PHP)
- Sending email using vb.net (VB.NET)
- Need Help Making a Form send to an email using PHP (PHP)
- how to send email alerts daily using msacess and asp.net1.1 (ASP.NET)
- how to send email using jsp (JSP)
- Send Email From my Application (ASP.NET)
- mailto in vb.net (VB.NET)
- send email (ASP.NET)
Other Threads in the VB.NET Forum
- Previous Thread: How can set windows state
- Next Thread: Web Browser and Media Problem
| Thread Tools | Search this Thread |
"crystal .net .net2005 30minutes 2008 access add advanced application array assignment basic binary box button buttons center click code combo connectionstring convert cpu data database databasesearch datagrid datagridview design designer dissertation dissertations dissertationthesis dosconsolevb.net editvb.net employees excel exists firewall folder image images isnumericfuntioncall listview login map math memory mobile module msaccess mssqlbackend mysql navigate net number opacity pan peertopeervideostreaming picturebox picturebox2 port print printpreview read record regex reports" reuse right-to-left save savedialog search serial socket sorting sqldatbase storedprocedure string temp textbox timer txttoxmlconverter upload useraccounts usercontol usercontrol vb vb.net vb.netcode vb.nettoolboxvisualbasic2008sidebar vbnet vista visual visualbasic visualbasic.net visualstudio.net web wpf xml





