|
It's called MAPI. As I said. Google for MAPI, there's.NET wrappers for it. I use one in C#, it works great.
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
Hi, this is code from a VBA project so is not actually .NET but it should give you a good idea on how to go about this. Hope it helps!
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
Persistable = 0 'NotPersistable
DataBindingBehavior = 0 'vbNone
DataSourceBehavior = 0 'vbNone
MTSTransactionMode = 0 'NotAnMTSObject
END
Attribute VB_Name = "COutlookMail"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit
'COutlookMail - Handles the sending of emails from Access using Outlook
'
'NOTE: Outlook must be available and running on the computer.
'
'==============================================
'This class uses structures to control the recipients and
'attachments. A more flexible and manageable model could be
'produced by the substitution of collection classes for these
'items, however this has the disadvantage that all the additional
'classes must also be present. The current model only requires
'a single class to be added to give mail functions.
'==============================================
Private oOutlookApp As Object
Private oMailItem As Object
'
'This class can be declared either with or without events
'If being used with events, the mail success flag event will
'be raised
Public Event MailSuccess(ByVal pState As Boolean)
'
Public Enum OFERecipientTypeConstants
rtcNormal = 1
rtcCarbonCopy = 2
rtcBlindCarbonCopy = 3
End Enum
'
Public Enum OFEAttachmentTypeConstants
atcSendAsFile = 1
atcSendAsLink = 2
End Enum
'
'-----------------------------------------------------------------------------------------------------------
Private mv_iAttachmentCount As Integer
Private mv_iRecipientCount As Integer
'-----------------------------------------------------------------------------------------------------------
Private mv_sLastErrorMessage As String
Private mv_lLastErrorNumber As Long
'
Private mv_bOutlookInitialseFailed As Boolean
'
Private strMail As OFEEmailDataStructure
'
'Attachments data structure
Private Type OFEAttachmentsDataStructure
FilePathAndName As String
DisplayName As String
AttachmentType As OFEAttachmentTypeConstants
End Type
'Recipients structure
Private Type OFEMailRecipientsStructure
RecipientName As String
RecipientType As OFERecipientTypeConstants
End Type
'Main mail structure
Private Type OFEEmailDataStructure
Attachments() As OFEAttachmentsDataStructure
Subject As String
Recipients() As OFEMailRecipientsStructure
MessageBody As String
MailSent As Boolean
SendErrors As Boolean
End Type
'
'Constants
Const mconstMAXRECIPIENTS As Integer = 10
Const mconstMAXATTACHMENTS As Integer = 10
'
Public Sub CreateNewMail(Optional ByVal SendCurrentMail As Boolean = False)
'Purpose: To initate a new email
'Inputs: Optional flag that sends any existing mail before initialising for a new one.
Dim bResult As Boolean
If SendCurrentMail = True Then
If strMail.MailSent = False Then
SendOutlookMail
End If
End If
ClearSTR
End Sub
Private Sub Class_Initialize()
'Creates the Outlook object
On Error Resume Next
Err.Clear
Set oOutlookApp = CreateObject("Outlook.Application")
If Err.Number <> 0 Then
'Events cannot be raised in the initialise event so a flag must be set
'for examination later
mv_lLastErrorNumber = Err.Number
mv_sLastErrorMessage = Err.Description
mv_bOutlookInitialseFailed = True
End If
ReDim strMail.Attachments(1 To mconstMAXATTACHMENTS) As OFEAttachmentsDataStructure
ReDim strMail.Recipients(1 To mconstMAXRECIPIENTS) As OFEMailRecipientsStructure
ClearSTR
On Error GoTo 0
End Sub
Private Sub Class_Terminate()
On Error Resume Next
Set oOutlookApp = Nothing
Set oMailItem = Nothing
On Error GoTo 0
End Sub
Public Sub SendOutlookMail(Optional ByVal RequireReadReceipt As Boolean = True, Optional ByVal RequireDeliveryReport As Boolean = False)
'Purpose: Sends the email and any attachments in the list
Dim iLoop As Integer
Dim oRecipient As Object
'Dim sWorkbook As String
Dim x As Variant
On Error GoTo ERROR_SOM
'Before Send call
'sWorkbook = ActiveWorkbook.Name
'
strMail.SendErrors = False
Set oMailItem = oOutlookApp.CreateItem(0)
With oMailItem
.Subject = strMail.Subject
If mv_iRecipientCount > 1 Then
For iLoop = 1 To mv_iRecipientCount
Set oRecipient = .Recipients.Add(strMail.Recipients(iLoop).RecipientName)
Select Case strMail.Recipients(iLoop).RecipientType
Case OFERecipientTypeConstants.rtcCarbonCopy
oRecipient.Type = 2
Case OFERecipientTypeConstants.rtcBlindCarbonCopy
oRecipient.Type = 3
End Select
Next
Else
.To = strMail.Recipients(1).RecipientName
End If
.Body = strMail.MessageBody
If mv_iAttachmentCount > 0 Then
For iLoop = 1 To mv_iAttachmentCount
If Trim(strMail.Attachments(iLoop).FilePathAndName) > "" Then
If strMail.Attachments(iLoop).AttachmentType = atcSendAsFile Then
.Attachments.Add strMail.Attachments(iLoop).FilePathAndName, 1, iLoop, strMail.Attachments(iLoop).DisplayName
Else
.Attachments.Add strMail.Attachments(iLoop).FilePathAndName, 4, iLoop, strMail.Attachments(iLoop).DisplayName
End If
End If
Next
End If
.ReadReceiptRequested = RequireReadReceipt
.OriginatorDeliveryReportRequested = RequireDeliveryReport
.Send
End With
strMail.MailSent = True
RaiseEvent MailSuccess(True)
'
Set oMailItem = Nothing
'
EXIT_SOM:
Exit Sub
ERROR_SOM:
strMail.SendErrors = False
mv_lLastErrorNumber = Err.Number
mv_sLastErrorMessage = Err.Description
RaiseEvent MailSuccess(False)
Resume EXIT_SOM
End Sub
Public Property Get InitialiseFailed() As Boolean
InitialiseFailed = mv_bOutlookInitialseFailed
End Property
Public Property Get LastErrorNumber() As Long
LastErrorNumber = mv_lLastErrorNumber
End Property
Public Property Get LastErrorMessage() As String
LastErrorMessage = mv_sLastErrorMessage
End Property
Private Sub ClearSTR()
Dim iLoop As Integer
'The mail sent flag is set to true so that an initialised empty mail does
'not get sent. Passing information to the properties will set the mail sent
'flag to False
strMail.MailSent = True
strMail.MessageBody = ""
strMail.Subject = ""
For iLoop = 1 To mconstMAXATTACHMENTS
strMail.Attachments(iLoop).DisplayName = ""
strMail.Attachments(iLoop).FilePathAndName = ""
Next
For iLoop = 1 To mconstMAXRECIPIENTS
strMail.Recipients(iLoop).RecipientName = ""
strMail.Recipients(iLoop).RecipientType = rtcNormal
Next
mv_iRecipientCount = 0
mv_iAttachmentCount = 0
End Sub
Public Function AddRecipient(ByVal NewRecipentName As String, ByVal NewRecipientType As OFERecipientTypeConstants) As Boolean
If mv_iRecipientCount < mconstMAXRECIPIENTS Then
mv_iRecipientCount = mv_iRecipientCount + 1
strMail.Recipients(mv_iRecipientCount).RecipientName = NewRecipentName
strMail.Recipients(mv_iRecipientCount).RecipientType = NewRecipientType
strMail.MailSent = False
AddRecipient = True
Else
mv_lLastErrorNumber = -1
mv_sLastErrorMessage = "The maximum number of recipients has been reached"
AddRecipient = False
End If
End Function
Public Function AddAttachment(ByVal NewFilePathAndName As String, ByVal NewAttachmentType As OFEAttachmentTypeConstants, Optional ByVal NewDisplayName As String = "") As Boolean
If mv_iAttachmentCount < mconstMAXATTACHMENTS Then
mv_iAttachmentCount = mv_iAttachmentCount + 1
strMail.Attachments(mv_iAttachmentCount).DisplayName = NewDisplayName
strMail.Attachments(mv_iAttachmentCount).FilePathAndName = NewFilePathAndName
strMail.Attachments(mv_iAttachmentCount).AttachmentType = NewAttachmentType
strMail.MailSent = False
AddAttachment = True
Else
mv_lLastErrorNumber = -2
mv_sLastErrorMessage = "The maximum number of attachments has been reached"
AddAttachment = False
End If
End Function
Public Property Get AttachmentCount() As Integer
AttachmentCount = mv_iAttachmentCount
End Property
Public Property Get RecipientCount() As Integer
RecipientCount = mv_iRecipientCount
End Property
Public Property Get AttachmentFile(ByVal Index As Integer) As String
If (Index < 1) Or (Index > mconstMAXATTACHMENTS) Then
AttachmentFile = ""
Else
AttachmentFile = strMail.Attachments(Index).FilePathAndName
End If
End Property
Public Property Get AttachmentDisplayName(ByVal Index As Integer) As String
If (Index < 1) Or (Index > mconstMAXATTACHMENTS) Then
AttachmentDisplayName = ""
Else
AttachmentDisplayName = strMail.Attachments(Index).DisplayName
End If
End Property
Public Property Get AttachmentType(ByVal Index As Integer) As Long
If (Index < 1) Or (Index > mconstMAXATTACHMENTS) Then
AttachmentType = 0
Else
AttachmentType = strMail.Attachments(Index).AttachmentType
End If
End Property
Public Property Get RecipientNameOrList(ByVal Index As Integer) As String
If (Index < 1) Or (Index > mconstMAXRECIPIENTS) Then
RecipientNameOrList = ""
Else
RecipientNameOrList = strMail.Recipients(Index).RecipientName
End If
End Property
Public Property Get RecipientType(ByVal Index As Integer) As Long
If (Index < 1) Or (Index > mconstMAXRECIPIENTS) Then
RecipientType = ""
Else
RecipientType = strMail.Recipients(Index).RecipientType
End If
End Property
Public Property Get SendErrors() As Boolean
SendErrors = strMail.SendErrors
End Property
Public Property Get MessageBody() As String
MessageBody = strMail.MessageBody
End Property
Public Property Let MessageBody(ByVal NewMessage As String)
strMail.MessageBody = NewMessage
strMail.MailSent = False
End Property
Public Property Get Subject() As String
Subject = strMail.Subject
End Property
Public Property Let Subject(ByVal NewSubject As String)
strMail.Subject = NewSubject
strMail.MailSent = False
End Property
David Loring
!! Keep Music Live !!
|
|
|
|
|
Sir/madam,
I am using the following code to send the mail using vb.net (Window Appications)
It is generating the following error.
Failure sending mail.
Try
Dim oMessage As MailMessage = New MailMessage
oMessage.Body = "MESSAGE COMES HERE"
oMessage.To.Add(TO_User_Email)
Dim oFrom As MailAddress = New MailAddress(FROM_User_Email)
oMessage.From = oFrom
oMessage.Subject = "SUBJECT COMES HERE"
'oMessage.IsBodyHtml = True
'oMessage.Priority = MailPriority.Normal
Dim oSMTP As SmtpClient = New SmtpClient("Localhost")
oSMTP.Send(oMessage)
Catch ex As Exception
End Try
Please help.
Thanks and regards
Pankaj
|
|
|
|
|
amaneet wrote: Dim oSMTP As SmtpClient = New SmtpClient("Localhost")
Are you sure you have a mail server running on your machine ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Sir,
Internet is running on my machine
Thanks and Regards
Pankaj
|
|
|
|
|
amaneet wrote: Internet is running on my machine
That is not enough. You need an SMTP server to send mail.
You can either install the SMTP server for IIS on your computer, or you can substitute the "localhost" in your code for the name of the SMTP server of your ISP (internet service provider). The second one is the safest bet, as some ISPs only allow sending mail through their SMTP server to prevent spam.
---
Year happy = new Year(2007);
|
|
|
|
|
im in school for programming and need some help learning vb trying to program tic tac toe in vb and all the downloads i have tried wont work in my particular program keeps showing errors
|
|
|
|
|
Sounds like you're downloading VB6 code. They are totally different.
No-one will do your homework for you ( well, I hope they won't ). What has your teacher asked you to do ? Is this a console program ? Text display on windows program ? Graphics driven ? 3D ? Do you hope to teach your game how to play against a player ? What code have you written ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
I am building a control I use to edit my company objects...but in some of my forms I do not want a certain button to be visible...I provided a property for the button that I can see at desgn time so that on those forms I can set the button to be invisible:
<Browsable(True), _
DefaultValue(GetType(DevExpress.XtraEditors.SimpleButton))> _
Public Property UpdateButton() As DevExpress.XtraEditors.SimpleButton
Get
Return btnUpdate
End Get
Set(ByVal value As DevExpress.XtraEditors.SimpleButton)
btnUpdate = value
End Set
End Property
But for some reason when I rebuild my project, I lose this setting and the control shows again...Any one have any idea what I could be doing wrong?
Pablo
while(1){DoTheDo();}
|
|
|
|
|
please help me, change font of windows system, EX: title font, menu...
please help me, thanks
kevil
|
|
|
|
|
Do you want to do it programmatically or manually?
If you want to do it manually, you can change the appereance in display settings.
- Go to Control Panel -> Display.
- Klik apppereance tab and then change it as you like.
if you want to program it you had to change the value in the registry by using registry object and set the value as you like.
|
|
|
|
|
I have a datagridview that have 7-8 columns. 3 of them is comboboxes with values that the user selects from.
I need the second of the comboboxes to change it lists of values depending of the values in the first. The third must change its values depending on the two first.
Anyone got any tip?
|
|
|
|
|
How about you make your own print preview dialog?
|
|
|
|
|
Thankyou so much for replying. you literally beat me to posting a new message to get some information about "printpreviewcontrol". i've searched everywhere and cannot find some source code or material to get me started to create my own PRINT PREVIEW. can you assist with some sites or material please.
Thanks
Robbo
|
|
|
|
|
Hello, I am a beginner in VB.net programming (or in general..) and I am getting this "NullReferenceException: Object reference not set to an instance of an object" when I try assigning strings to an array..what am I missing?...if I make it an arraylist instead, it works ok except that things are stored in a way that I do not really know how to work with. What is the difference between array and arraylist in vb.net?.. Thanks all for your help!
Below is my code that gives me the null reference error.
Imports System.IO
Public Class Form1
Dim isotope, mass_frac, Sp_A, gammaE, absCoeff, attenCoeff As ArrayList
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Dim oFile As System.IO.File
Dim oRead As System.IO.StreamReader
Dim templine As String = Nothing
Dim strInp() As Array = Nothing
Dim PI(), PIstrList() As String
Dim i, j As Integer
Dim l As Integer = 0
Dim k As Char
isotope = New ArrayList()
Dim saparator() As Char = {" "c}
Try
'Load information file
oRead = File.OpenText("myfile.inf")
Do Until oRead.EndOfStream
templine = oRead.ReadLine
'get first char from the line
k = Mid(templine, 1, 1)
If (k <> "*" And k <> " "c) Then
strInp(l) = Split(templine, vbTab)
l += 1
End If
Loop
' System.Text.RegularExpressions.Regex()
Catch ex As Exception
MsgBox(Convert.ToString(ex))
End
End Try
End Sub
|
|
|
|
|
joon52 wrote: Dim strInp() As Array = Nothing
Your array is nothing, and that's what the error is telling you.
Use an array only if you know exactly how many elements you will have. Otherwise, use ArrayList. You should create a typed array, if at all possible.
If you're just starting, you should go for VB.NET 2005, where you can specify a type for your list parameters, using the generic List class. You should never use ArrayList, it should have never existed.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
HI All - I few days ago I posed a question about this and got an answer, but in the end this particular method did not work for me. I have managed to find a way to do it and I thought I would share it. Hope this helps someone.
In the CellPainting event..........
Dim greenBackBrush As New SolidBrush(Color.LightGreen)
Dim gridBrush As New SolidBrush(Me.dgvAvail.GridColor)
Dim gridLinePen As New Pen(gridBrush)
Dim nsCellValue As Single = 0
Dim nsMaxValue As Single = 0
Dim sf As New StringFormat
sf.FormatFlags = StringFormatFlags.NoWrap Or StringFormatFlags.FitBlackBox
sf.LineAlignment = StringAlignment.Center
sf.Alignment = StringAlignment.Center
sf.Trimming = StringTrimming.None
'This cell shown Green
' Erase the cell.
e.Graphics.FillRectangle(greenBackBrush, e.CellBounds)
' Draw the grid lines (only the right and bottom lines;
' DataGridView takes care of the others).
e.Graphics.DrawLine(gridLinePen, e.CellBounds.Left, _
e.CellBounds.Bottom - 1, e.CellBounds.Right - 1, _
e.CellBounds.Bottom - 1)
e.Graphics.DrawLine(gridLinePen, e.CellBounds.Right - 1, _
e.CellBounds.Top, e.CellBounds.Right - 1, _
e.CellBounds.Bottom)
If Not (e.Value Is Nothing) Then
Dim g As Graphics = e.Graphics
Dim r As System.Drawing.Rectangle
r.Width = (e.CellBounds.Right - 2) - (e.CellBounds.Left + 2)
r.Height = (e.CellBounds.Bottom - 2) - (e.CellBounds.Top + 2)
r.X = e.CellBounds.X + 2
r.Y = e.CellBounds.Y + 2
e.Graphics.TextRenderingHint = Drawing.Text.TextRenderingHint.AntiAliasGridFit
e.Graphics.DrawString(CStr(nsCellValue), e.CellStyle.Font, Brushes.Black, r, sf)
r = Nothing
End If
See the article for the full subroutine code
-- modified at 13:41 Saturday 20th January, 2007
David Loring
!! Keep Music Live !!
|
|
|
|
|
Hello,
My customer wants to be able to update the program and download only the updates from the server.
The customer wants to install the application and then download updates when they are available. And install them without having to reinstall the program.
I started using the clickonce which works ok for this situation. However, the customer did not like this as it always installs in the default documents and setting directory, and the updates that are downloaded as the same size as the initial program size. As the updates are only small the customer only wants to download those updates so it will be quick to download and quick to install.
Is there another method to be able to do this, maybe some free third party, or can you configure the MSI to do this.
The customer would like something like norton anti-virus where only the updates are installed only.
Many thanks in advance,
Steve
|
|
|
|
|
Well it really all depends on what your application does. If you have to re-write code blocks & recompile your app then a re-install is the way to go. Remember that anti-virus products more often than not download updates to the virus definition library which is not hard-coded into the app itself but rather a resource that the app makes use of.
What is it that needs to be updated in your app? Is it a resource? If so then, yes, I think you could give your customer what he wants.
|
|
|
|
|
Hello,
I am creating a PDA application using the CF 2.0 that will use a datagrid and will display time in one of the columns. The column is called "ScheduledTime" and in the sql server 2005 database the datatype is datetime.
I would like to format the time to display e.g. 21:45 24hr format.
I think the datagrid is very limited when using the CF for mobile applications as the property "format" doesn't exist for this. See my code below.
I am wondering is there another way to format time in a datagrid column using the CF 2.0.
<vbcode>Me.grdSupportContracts.DataSource = ds.Tables(0)
Dim dgtbc As DataGridTextBoxColumn
dgtbc = CType(Me.grdSupportContracts.TableStyles(0).GridColumnStyles(3), DataGridTextBoxColumn)
dgtbc.Format 'Doesn't have the format property
Many thanks in advance,
Steve
|
|
|
|
|
Hello there
I have a little question...
I have seen many little apps that can retrieve your internet connection's username and password, for connections like ADSL, Dial-Up, VPN's, e.t.c.
So I'd like to ask if anyone knows how can I do that myself using VS2005 ???
|
|
|
|
|
how can i get the processorId using VB.NET
|
|
|
|
|
|
Hi Dear all
Would you please give me a sample code(s) that show(s) using of filter method in vb.net to limit datasource data? I dont want to use SQL instructions to do that, so if you have any suggestions to do that with vb.net code please help me.
Many Thanks
|
|
|
|
|
Mansourgh wrote: I dont want to use SQL instructions to do that
Why not ? You're asking 'how do I do things the hard and slow way' ?
you can iterate over your collection and knock out the items you don't want. There's no other way I can think of, filtering with SQL is supported on the code end as well as on the DB, but you don't want to use SQL for some strange reason.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|