[dba-VB] Smtp mail from vb.net

Seth Galitzer sgsax at ksu.edu
Fri Aug 19 10:13:55 CDT 2005


I built a demo for Access that does this using a few VB sites.

This one has a fully-function VB app that uses the MS Winsock ActiveX 
control to do the TCP/IP stuff:
http://www.vbip.com/winsock/winsock_uucode_02.asp

I modified it using the following socket class to replace the dependency 
on the MS Winsock control:
http://www.vbip.com/winsock-api/csocket-class/csocket-class-01.asp

I also put together a VB6 app that includes my modifications used in the 
  Access demo.  I suspect it should port over to .net relatively easily.

You can get both from the downloads area on my website.

Seth

John W. Colby wrote:
> 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/
> 
> 
> _______________________________________________
> dba-VB mailing list
> dba-VB at databaseadvisors.com
> http://databaseadvisors.com/mailman/listinfo/dba-vb
> http://www.databaseadvisors.com
> 

-- 
Seth Galitzer                   sgsax at ksu.edu
Computing Specialist            http://puma.agron.ksu.edu/~sgsax
Dept. of Plant Pathology
Kansas State University



More information about the dba-VB mailing list