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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Email

Status
Not open for further replies.

JohnnyLong

Programmer
Sep 27, 2002
97
GB
I've been trying to use the Outlook object library to send emails but have discovered problems due to different clients using different versions of Outlook. I've seen the FAQ on Automatic Email using SMTP. Will I be able to send multiple Cc's/BCcs and attachments using this method?

John.
 
Hey John try this out, it works nicely for me all you need to do is put in the correct smtp server, and pass the email body as a string, the attachment/s locations as a string seperated by "," the from email, and the to address which if you changed those to an array you could pass multiple in the to or add a cc string as well, and then finally the subject as string.

Let me know if this helps or have any questions about it.

Also might want to remove the file delete part at the bottom, if you are planning on keeping the attachments.

-Matt

Function esendEmail(ByVal sBody As String, ByVal sEmailAttach As String, _
ByVal sFromEmail As String, ByVal sToEmail As String, ByVal sEmailSubject As String) As Boolean
Try

Dim oEmail As New System.Web.Mail.MailMessage()
Dim arTmp As Array
Dim x As Int16
Dim fi As IO.FileInfo

oEmail.BodyFormat = Web.Mail.MailFormat.Html
oEmail.Body = sBody

arTmp = sEmailAttach.Split(",")

For x = 0 To arTmp.Length - 1
Dim EmailAttach As New System.Web.Mail.MailAttachment(arTmp(x).ToString)
fi = New IO.FileInfo(arTmp(x).ToString)
oEmail.Attachments.Add(EmailAttach)
Next

oEmail.From = sFromEmail
oEmail.To = sToEmail
oEmail.Subject = sEmailSubject

Dim oSendEmail As Web.Mail.SmtpMail
oSendEmail.SmtpServer = "exchange.server.com"
oSendEmail.Send(oEmail)

For x = 0 To arTmp.Length - 1
Dim EmailAttach As New System.Web.Mail.MailAttachment(arTmp(x).ToString)
fi = New IO.FileInfo(arTmp(x).ToString)
If fi.Exists Then fi.Delete()
'Delete the File
Next

Return True
Catch ex As Exception
Return False
End Try
End Function
 
Thanks for that. Works well. Only problem I have is identifying the From address. Do you know how to capture each users email address or do you store this in the db?

John.
 
I have it stored in the db for what i'm using it for. What are you trying to capture the email address from?

-Matt
 
I just wondered if it was possible to capture the address either from Outlook on the users machine or from the mail server. Not a problem as I will store each address on the db.
Thanks,

John.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top