John W. Colby
jwcolby at colbyconsulting.com
Thu Aug 18 20:57:47 CDT 2005
I'm trying to get .net to send email for me without going through Outlook. I found the following on the web: Imports System.Web.Mail Imports System.IO Module basMail 'TWO FUNCTIONS 'SAME EXCEPT FIRST TAKES A STRING FOR ATTACHMENT 'SECOND TAKES AN ARRAY LIST SO YOU CAN SEND MULTIPLE 'ATTACHMENTS 'FROM: Email address FRom 'TO: EMAIL address To 'Subject: Subject; Body: MessageText 'Optional CC, BCC: CC and bcc recipients 'SMTPSERVER: Optional, if not specified 'local machine is used 'AttachmentFile (first function: Optional, file name) 'AttachmentFiles (second function: Optional, list of 'attachments in form of an array list) Public Sub SendMailOneAttachment(ByVal From As String, _ ByVal sendTo As String, ByVal Subject As String, _ ByVal Body As String, _ Optional ByVal AttachmentFile As String = "", _ Optional ByVal CC As String = "", _ Optional ByVal BCC As String = "", _ Optional ByVal SMTPServer As String = "Mail.optonline.com") Dim myMessage As MailMessage Try myMessage = New MailMessage() With myMessage .To = sendTo .From = From .Subject = Subject .Body = Body .BodyFormat = MailFormat.Text 'CAN USER MAILFORMAT.HTML if you prefer If CC <> "" Then .Cc = CC If BCC <> "" Then .Bcc = "" If FileExists(AttachmentFile) Then _ .Attachments.Add(AttachmentFile) End With If SMTPServer <> "" Then _ SmtpMail.SmtpServer = SMTPServer SmtpMail.Send(myMessage) Catch myexp As Exception Throw myexp End Try End Sub When I call the function not passing in an smtp server, nothing obvious happens, no exception thrown. No email is delivered to my mail box though. If I pass in mySMTP server for outlook mail.optonline.com, it throws an error "system.web.httpexception - could not access cdo.message object". Any ideas? If not does anyopne have a drop in function for sending email that they can walk me through using?? John W. Colby www.ColbyConsulting.com Contribute your unused CPU cycles to a good cause: http://folding.stanford.edu/