|
-
Jul 3rd, 2008, 08:52 AM
#1
Thread Starter
Fanatic Member
[02/03] Send email from form?
Hi every one
Im hoping someone out there could offer me some help please.
I have a program which is linked to a database, I have the program working perfectly as it saves and derives data from the database. The question I want to ask is simple would it be possible when the user clicks on 'Save' and the data gets saved in to the database, outlook opens and the information is taken from the textboxes and placed in body text field (where you normally write out your email), with the address bar automatically flled in ready for an email to be sent (If it sends it straight away that would be better.)
Any help please? if its too much then please tell me.
*It doesnt have to be outlook if I could send it from my form that would be just as good.
-
Jul 3rd, 2008, 09:54 AM
#2
Re: [02/03] Send email from form?
Hi,
Here you could already find some good information.
http://support.microsoft.com/kb/314201
Wkr,
sparrow1
-
Jul 3rd, 2008, 10:54 AM
#3
Thread Starter
Fanatic Member
Re: [02/03] Send email from form?
Thanks for your help but it keeps breaking on the
SmtpMail.Send(oMsg)
line with the following error:
An unhandled exception of type 'System.Web.HttpException' occurred in system.web.dll
Additional information: Could not create 'CDO.Message' object.
Any ideas to maybe why? Thanks
-
Jul 3rd, 2008, 11:07 AM
#4
Re: [02/03] Send email from form?
Hi,
I think it's only for file attachments who have a path like in the example:
vb Code:
' TODO: Replace with path to attachment. Dim sFile As String = "C:\temp\Hello.txt" Dim oAttch As MailAttachment = New MailAttachment(sFile, MailEncoding.Base64) oMsg.Attachments.Add(oAttch) ' TODO: Replace with the name of your remote SMTP server. SmtpMail.SmtpServer = "MySMTPServer" SmtpMail.Send(oMsg)
So, what you can try is to sent a file located on your disk and sent it.
Just to see if the error still exist.
Wkr,
sparrow1
-
Jul 3rd, 2008, 11:21 AM
#5
Thread Starter
Fanatic Member
Re: [02/03] Send email from form?
Hi Sparrow I did create the text file in the C: temp directory, I think the problem might be on the SMTP server side however I did enter the correct name for that.
Thanks
-
Jul 3rd, 2008, 11:29 AM
#6
Re: [02/03] Send email from form?
Hi,
What outgoing server did you used:
vb Code:
relay. ?????? . com ' this is the one like your email account!
Wkr,
sparrow1
-
Jul 3rd, 2008, 12:03 PM
#7
Thread Starter
Fanatic Member
Re: [02/03] Send email from form?
Huh sorry I dont understand, would it possible for you to create me a quick example so I can have a look at it please?
I would appreciate it very much.
-
Jul 3rd, 2008, 05:05 PM
#8
Thread Starter
Fanatic Member
Re: [02/03] Send email from form?
Any one
-
Jul 3rd, 2008, 05:32 PM
#9
Re: [02/03] Send email from form?
Regarding the error message you were getting you might want to have a read of this and do some research
http://support.microsoft.com/kb/910360
-
Jul 4th, 2008, 10:45 AM
#10
Re: [02/03] Send email from form?
 Originally Posted by frankwhite
Huh sorry I dont understand, would it possible for you to create me a quick example so I can have a look at it please?
I would appreciate it very much.
Hi,
Here's an example how to use System.Web.Mail.
.Net Code:
Imports System.Web.Mail
Public Class Form2
Inherits System.Windows.Forms.Form
Dim obj As _
System.Web.Mail.SmtpMail ' Variable which will send the mail
Dim Attachment As System.Web.Mail.MailAttachment 'Variable to store the attachments
Dim Mailmsg As New System.Web.Mail.MailMessage() 'Variable to create the message to send
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
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
OpenFileDialog.CheckFileExists = True
OpenFileDialog.Title = "Select file(s) to attach"
OpenFileDialog.ShowDialog()
For Counter = 0 To UBound(OpenFileDialog.FileNames)
lstAttachment.Items.Add(OpenFileDialog.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.Remove(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
'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
obj.SmtpServer = txtSMTPServer.Text ' your local outgoing SMTP server
'Multiple recepients can be specified using ; as the delimeter
Mailmsg.To = txtTo.Text
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
Mailmsg.Subject = txtSubject.Text
For Counter = 0 To lstAttachment.Items.Count - 1
Attachment = New MailAttachment(lstAttachment.Items(Counter))
Mailmsg.Attachments.Add(Attachment)
Next
Mailmsg.Body = txtMessage.Text
obj.Send(Mailmsg)
End Sub
End Class
-
Oct 22nd, 2008, 04:33 AM
#11
New Member
Re: [02/03] Send email from form?
 Originally Posted by sparrow1
Hi,
Here's an example how to use System.Web.Mail.
.Net Code:
Imports System.Web.Mail
Public Class Form2
Inherits System.Windows.Forms.Form
Dim obj As _
System.Web.Mail.SmtpMail ' Variable which will send the mail
Dim Attachment As System.Web.Mail.MailAttachment 'Variable to store the attachments
Dim Mailmsg As New System.Web.Mail.MailMessage() 'Variable to create the message to send
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
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
OpenFileDialog.CheckFileExists = True
OpenFileDialog.Title = "Select file(s) to attach"
OpenFileDialog.ShowDialog()
For Counter = 0 To UBound(OpenFileDialog.FileNames)
lstAttachment.Items.Add(OpenFileDialog.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.Remove(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
'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
obj.SmtpServer = txtSMTPServer.Text ' your local outgoing SMTP server
'Multiple recepients can be specified using ; as the delimeter
Mailmsg.To = txtTo.Text
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
Mailmsg.Subject = txtSubject.Text
For Counter = 0 To lstAttachment.Items.Count - 1
Attachment = New MailAttachment(lstAttachment.Items(Counter))
Mailmsg.Attachments.Add(Attachment)
Next
Mailmsg.Body = txtMessage.Text
obj.Send(Mailmsg)
End Sub
End Class
good job, thanks for good share
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|