Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Send Email and Attachment using VB.Net

Posted on 2010-11-20
20
Medium Priority
?
976 Views
Last Modified: 2013-11-12
I am looking for an example of auto-email
to populate:
   TO,CC,BODY.
In the body, a standard message is structured. Also it would add the attachment which is in the
C:\Sent\.. folder
My email system is  Groupwise/Novell...
Do I need to use somekind of Group wise Type Library? Thanks
0
Comment
Question by:zachvaldez
  • 10
  • 4
  • 3
  • +2
20 Comments
 
LVL 7

Accepted Solution

by:
twol earned 800 total points
ID: 34181856
from
http://www.freevbcode.com/ShowCode.asp?ID=5486

Imports System.Web.Mail
Imports System.IO

   '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 = "")

        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

Public Sub SendMailMultipleAttachments(ByVal From As String,_
    ByVal sendTo As String, ByVal Subject As String, _
    ByVal Body As String, _
    Optional ByVal AttachmentFiles As ArrayList = Nothing, _
    Optional ByVal CC As String = "", _
    Optional ByVal BCC As String = "", _
    Optional ByVal SMTPServer As String = "")

        Dim myMessage As MailMessage
        Dim i, iCnt As Integer

        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 Not AttachmentFiles Is Nothing Then
                    iCnt = AttachmentFiles.Count - 1
                    For i = 0 To iCnt
                        If FileExists(AttachmentFiles(i)) Then _
                          .Attachments.Add(AttachmentFiles(i))
                    Next

                End If

            End With

            If SMTPServer <> "" Then _
              SmtpMail.SmtpServer = SMTPServer
            SmtpMail.Send(myMessage)


        Catch myexp As Exception
            Throw myexp
        End Try
    End Sub

    Private Function FileExists(ByVal FileFullPath As String) _
     As Boolean
        If Trim(FileFullPath) = "" Then Return False

        Dim f As New IO.FileInfo(FileFullPath)
        Return f.Exists

    End Function

Open in new window

0
 
LVL 21

Expert Comment

by:Alfred A.
ID: 34182188
0
 

Author Comment

by:zachvaldez
ID: 34187240
Does this code need a reference to Groupwise/novell type library just like when doing a Outlook message?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 7

Expert Comment

by:twol
ID: 34188752
This will give you specific FAQs:

http://www.systemwebmail.com/allfaq.aspx
0
 

Author Comment

by:zachvaldez
ID: 34189157
Thanks for the article. It significantly talks about CDO which is Outlook based.
Im using groupwise/novell.
0
 
LVL 3

Expert Comment

by:Henry Rohlfs
ID: 34189308
Start by going to Novell's developer site for GroupWise: http://www.novell.com/developer/develop_to_groupwise.html. There you can find the SDK for GroupWise and code examples in a few different languages.

Here's a support article on the GroupWise API with VB examples: http://support.novell.com/techcenter/articles/ana20000813.html

And here's a recent Novell forum post on the subject: http://forums.novell.com/novell-product-support-forums/groupwise/version-independent-forums/gw-messenger/389682-visual-basic-sample-groupwise-messenger-api.html

Don't forget that the GroupWise client must be installed for your API code to work.
0
 

Author Comment

by:zachvaldez
ID: 34189382
thanks,
>>>>Don't forget that the GroupWise client must be installed for your API code to work
Since I am using groupwise for email,does that mean the clent is already installed in my PC?
Just to clarify...
0
 
LVL 3

Expert Comment

by:Henry Rohlfs
ID: 34189417
If your email client has the selection "About GroupWise" under the "Help" menu, then yes the GroupWise client is installed. If you use Outlook to access your GroupWise emails, then you may need to install the GroupWise client on your pc.

Which version of GroupWise do you use?
0
 

Author Comment

by:zachvaldez
ID: 34189450
version 8
0
 
LVL 3

Expert Comment

by:Henry Rohlfs
ID: 34189472
Perfect. There isn't much difference in the API between version 8 and prior versions, but the forum post I gave you shows code used in a v8 environment.
0
 

Author Comment

by:zachvaldez
ID: 34247329
Th examples look like classic VB and not VB.NET. BUt I could be wrong
0
 
LVL 3

Expert Comment

by:Henry Rohlfs
ID: 34258445
Ok, I searched Novell's Cool Solutions and found this article that is VB.NET specific.

http://www.novell.com/coolsolutions/tools/14096.html
0
 

Author Comment

by:zachvaldez
ID: 34263540
How does Groupwise API work with VB.NET?
How is it structured in code?
What namespace is declared in vb code?
0
 
LVL 83

Assisted Solution

by:CodeCruiser
CodeCruiser earned 800 total points
ID: 34265106
0
 

Author Comment

by:zachvaldez
ID: 34267396
thanks for getting back to this question. Im still at a lost to how to mix gw and vb.net
0
 

Author Comment

by:zachvaldez
ID: 34267609
this link brings in an empty page
http://www.novell.com/coolsolutions/trench/9694.html

0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 34269070
The link contains a link to the download page for sample project


Download it here: http://www.ipdg3.com/sourcecoderesults.php?option=sourcecode&id=000464 
0
 

Author Comment

by:zachvaldez
ID: 34269846
I get page not found and instruction to upload web site or something
0
 

Author Comment

by:zachvaldez
ID: 34337252
Try
            myMessage = New MailMessage()
            With myMessage
                .To = sendTo>>> its telling its readonly
0
 
LVL 83

Assisted Solution

by:CodeCruiser
CodeCruiser earned 800 total points
ID: 34337408
.To is a collection.

Use

.To.Add(sendTo)
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses
Course of the Month21 days, 6 hours left to enroll

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question