Solved

Send Email and Attachment using VB.Net

Posted on 2010-11-20
20
896 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 200 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:Alfred1
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
 
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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 200 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 200 total points
ID: 34337408
.To is a collection.

Use

.To.Add(sendTo)
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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 …
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

743 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now