[dba-VB] Smtp mail from vb.net

John W. Colby jwcolby at colbyconsulting.com
Thu Aug 18 22:08:35 CDT 2005


I am attempting to create a system that will take data from a database,
export it into a text file, then send that file as an attachment to an email
to an insurance company.  Later I will need to get an FTP channel going to
send the file to an FTP site.  I would prefer to avoid using Outlook, i.e.
just have DotNet directly send the email.

My home office is connected to the internet via the cable company.  They do
port 25 blocking, forcing me to send to their SMTP server (from here at my
office).  It was for that reason that I sent to mail.optonline.com, as that
is the SMTP server address used by my Outlook (from my home office).  I am
actually in the process of switching to a new hosting company that will
allow me to use an alternate port to transmit email.  That will still
require me to hit that company's SMTP server, but at least I can send from
anywhere I may be working to the same SMTP address.  As it currently stands,
I have to constantly futz with the SMTP server address as I move my laptop
from my home to my client to my sister-in-law etc.  All three of those
locations goes through a ISP that performs port 25 blocking.

Anyway.....

I am trying to set up email for my vb.net program.  It would be nice if it
just worked, from wherever I plopped it down.  And, of course, I do not
understand anything about email, SMTP servers, or even vb.net.  I guess that
would make me jack of all trades...  ;-)  Or at least master of none of
these.

Someday I hope to be able to say I at least understand the vb.net part.

John W. Colby
www.ColbyConsulting.com 

Contribute your unused CPU cycles to a good cause:
http://folding.stanford.edu/

-----Original Message-----
From: dba-vb-bounces at databaseadvisors.com
[mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Eric Barro
Sent: Thursday, August 18, 2005 10:55 PM
To: dba-vb at databaseadvisors.com
Subject: RE: [dba-VB] Smtp mail from vb.net


If you are trying to send via mail.optonline.com and it resolves to one of
your machines on the internal network it won't work. Try using localhost
which resolves to 127.0.0.1 (assuming that the mail server is your local
machine) or the internal IP of the smtp server. 

-----Original Message-----
From: dba-vb-bounces at databaseadvisors.com
[mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of John W. Colby
Sent: Thursday, August 18, 2005 6:58 PM
To: VBA
Subject: [dba-VB] Smtp mail from vb.net

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



 

 
----------------------------------------------------------------
The information contained in this e-mail message and any file, document,
previous e-mail message and/or attachment transmitted 
herewith is confidential and may be legally privileged. It is intended
solely for the private use of the addressee and must not be 
disclosed to or used by anyone other than the addressee. If you receive this
transmission by error, please immediately notify the 
sender by reply e-mail and destroy the original transmission and its
attachments without reading or saving it in any manner.  If you 
are not the intended recipient, or a person responsible for delivering it to
the intended recipient, you are hereby notified that any 
disclosure, copying, distribution or use of any of the information contained
in or attached to this transmission is STRICTLY 
PROHIBITED. E-mail transmission cannot be guaranteed to be secure or error
free as information could be intercepted, corrupted, 
lost, destroyed, arrive late or incomplete, or contain viruses. The sender
therefore does not accept liability for any errors or omissions in the
contents of this message, which arise as a result of 
email transmission. Users and employees of the e-mail system are expressly
required not to make defamatory statements and not 
to infringe or authorize any infringement of copyright or any other legal
right by email communications. Any such communication is 
contrary to company policy. The company will not accept any liability in
respect of such communication.

_______________________________________________
dba-VB mailing list
dba-VB at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/dba-vb
http://www.databaseadvisors.com







More information about the dba-VB mailing list