Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Send Email and Attachment using VB.Net

Posted on 2010-11-20
20
908 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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
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 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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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 …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

829 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