Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sending email. 1

Status
Not open for further replies.

toon10

Programmer
Mar 26, 2004
303
0
0
DE
Hi

I’m using the System.Web.Mail class to send emails from my .net application. Here’s the code for my send button.

Private Sub btnSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSend.Click
Dim Counter As Integer
If txtSubject.Text = "" Then
MsgBox("Enter the email subject", MsgBoxStyle.Information,
"Send Email")
Exit Sub
End If
obj.SmtpServer = "xxx.xxx.x.xxx"
Mailmsg.To = MyVarTo 'to
Mailmsg.From = MyVarFrom 'from
Mailmsg.BodyFormat = MailFormat.Html
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

Although this works fine, I want to be able to store the email in the sent items folder of the default user of whichever PC the mail is sent from on Exchange. I’ve never seen this done before using this method. Does anyone know if it’s possible and how I could achieve this?

Thanks
Andrew
 
it looks like you are sending it using an smtp server, i think this is something different from sending it via exchange? perhaps you need cdonts or is it cdo??
 
Yeah, I've used cdonts in the past (we had a server without Exchange on it!) Still not sure how to do what I want using cdonts.

Andrew
 
You can only do this if you use exchange (or outlook) to actually send the message, which is actually pretty easy.

There are many resources online for sending messages though outlook and exchange and a few ways of doing it.

Start at or have a look around the microsoft MSDN stuff

The only example i can give is one used to access the calendar, but they work on a similar basis so it should give you a place to start


olApp = New Outlook.Application
olNamespace = olApp.GetNamespace("MAPI")
olFolder = olNamespace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar)
Dim storeID As String = olFolder.StoreID
olAppointment = olApp.CreateItem(Outlook.OlItemType.olAppointmentItem)

'Set the various properties
olAppointment.Start = ApptToCreate.DateBegin
olAppointment.End = ApptToCreate.DateEnd
olAppointment.Subject = ApptToCreate.Text
olAppointment.Body = ApptToCreate.AppointmentDescription
olAppointment.AllDayEvent = ApptToCreate.AllDay
olAppointment.Save()
 
Oh right, cheers.

I'll take a look.

Thanks
Andrew
 
Thanks shatch, that works a treat. Just the starting point I was after.

Here's my new code on the send button in case anyone else wants to do the same...

Private Sub btnOutlook_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOutlook.Click
Dim Counter As Integer
Dim oNewMail As Outlook.MailItem
Dim objOLApp As Outlook.Application
Dim oAttachment
Dim x As Short

If txtSubject.Text = "" Then 'validate data
MsgBox("Enter the email subject", _
MsgBoxStyle.Information, "Send Email")
Exit Sub
End If

objOLApp = New Outlook.Application
oNewMail = objOLApp.CreateItem
(Outlook.OlItemType.olMailItem)
With oNewMail
.Subject = txtSubject.Text
.Body = txtBody.Text
.Recipients.Add("andrew.young@fone- _
logistics.co.uk")
For Counter = 0 To lstAttachment.Items.Count - 1
oAttachment = .Attachments.Add(lstAttachment.Items _
(Counter))
Next
.Send()
End With

oNewMail = Nothing
objOLApp = Nothing

'insert code to copy contents of form to database to keep
'track of and make visible to other users, emails sent to
'customers!

End Sub

Andrew
 
Hi.. How different would it be trying to place the email in a default folder in a public folder ?

Thanks
 
How can this be done if Outlook isn't actually installed on the PC? We use OWA to access our emails, and the System.Web.Mail class isn't available in the Imports list...
 
You cannot import system.web.mail unless you have created a reference in the project to system.web. Once done this will be available in the imports statement
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top