Skall sända ett mail från VB.Net genom Outlook 2002 i Windows XP. Får ett msgbox i outlook som säger att "Ett program försöker att automatiskt skicla e-post åt dig. Tillåter Du detta?". Detta är naturligtvis en säkerhetsinställning, men var skulle man kunna hitta detta. Har kollat i outlook med en KB166557 från MS, kan inte lösa detta. Hej, denna funkar på min dator med iis installerat, jag har inte förstått detta riktigt med CDONTS men med iis i datorn funkar det utan frågor. Följande kod är lite mer "ren" .Net än era lösningar, men om den löser ditt säkerhetsproblem vet jag inte. Sen använder ju inte denna lösning Outlooks inställningar för att skicka mail, vilken kan vara ett problem, beroende på hur ditt program ska fungera. Kanske hjälper det en bit på vägen... utdrag från DEJASända mail vi VB
MVH
Magnus Buhre
Dim Outlook, Mail, tx, di, sum
tx = "AlarmEvent.AlarmItem.AlarmText"
di = "AlarmEvent.AlarmItem.DataItem"
sum = tx & " " & di
Set Outlook = createobject("Outlook.Application")
Set Mail = Outlook.createitem(0)
Mail.To = "Magnus.buhre@@beijer.se"
Mail.subject = "AlarmEvent.EventTime"
Mail.body = sum
Mail.Display
Mail.Send
Set Outlook = Nothing
Set Mail = NothingSv: Sända mail vi VB
Ser NU att jag svarat på .net-fråga men det kanske funkar där med?
<code>
Private Sub Command1_Click()
'--------------------------------------------------------------------
'
' Mailout using CDONTS.NewMail
'
'--------------------------------------------------------------------
' declare all variables
Dim objSendMail
Dim strTo, strFrom
Dim strSubject, strBody
' mail constants (some are for reference)
Const CdoBodyFormatHTML = 0 ' Body property is HTML
Const CdoBodyFormatText = 1 ' Body property is plain text (default)
Const CdoMailFormatMime = 0 ' NewMail object is in MIME format
Const CdoMailFormatText = 1 ' NewMail object is plain text (default)
Const CdoLow = 0 ' Low importance
Const CdoNormal = 1 ' Normal importance (default)
Const CdoHigh = 2 ' High importance
strFrom = "DIN ADRESS" ' change to your email
strTo = "ADRESS DET SKA TILL" ' change to the recipient's
strSubject = "VB ERROR/No UPPDATE" ' change to your subject
' this line calls the ReadFile() function to read the page contents
strBody = ReadFile("mailout.txt") 'DENNA RAD SKA HA RÄTT SÖKVÄG TILL FILEN
'DENNA FIL BLIR MAILETS INNEHÅLL
' this line calls the MakePage() function to format the page as HTML
strBody = MakePage(strSubject, strBody)
' the following section creates the mail object and sends the mail
Set objSendMail = CreateObject("CDONTS.NewMail")
objSendMail.From = strFrom
objSendMail.To = strTo
objSendMail.Subject = strSubject & " (" & Date & ")"
objSendMail.Body = strBody
objSendMail.BodyFormat = CdoBodyFormatHTML
objSendMail.MailFormat = CdoMailFormatMime
objSendMail.Importance = CdoNormal
objSendMail.Send
Set objSendMail = Nothing
End Sub
' this function returns a properly formatted HTML page
Function MakePage(txtSubject, txtBody)
Dim txtTemp
txtTemp = "<HTML>" & vbCrLf
txtTemp = txtTemp & "<HEAD><TITLE>"
txtTemp = txtTemp & txtSubject
txtTemp = txtTemp & "</TITLE></HEAD>" & vbCrLf
txtTemp = txtTemp & "<BODY>" & vbCrLf
txtTemp = txtTemp & "<H2>" & txtSubject & "</H2>" & vbCrLf
txtTemp = txtTemp & txtBody & vbCrLf
txtTemp = txtTemp & "</BODY>" & vbCrLf
txtTemp = txtTemp & "</HTML>"
MakePage = txtTemp
End Function
' this function opens a file and returns the file's contents
Function ReadFile(txtFile)
Dim txtTemp, objFS, objFL
Set objFS = CreateObject("Scripting.FileSystemObject")
Set objFL = objFS.OpenTextFile(txtFile)
Do While Not objFL.AtEndOfStream
txtTemp = txtTemp & objFL.ReadLine
txtTemp = txtTemp & vbCrLf
Loop
objFL.Close
Set objFS = Nothing
ReadFile = txtTemp
End Function
</code>Sv: Sända mail vi VB
/Per Hultqvist
<code>
Imports System.Web.Mail
//create & instantiate mail object
Dim mail As MailMessage = New MailMessage()
Dim att As MailAttachment = New MailAttachment(Path)
//attach to, subject, attachment & body
mail.Attachments.Add(att)
mail.From = "from@mydomain.com"
mail.To = "to@yourdomain.com"
mail.Subject = "Subject"
mail.Body = "The body goes here!"
mail.BodyFormat = MailFormat.Text
// set the default smtp server & send it
SmtpMail.SmtpServer = "yourSMTP.yourdomain.com"
SmtpMail.Send(mail)
</code>Sv: Sända mail vi VB
**********************************************************************
If you're a standalone user, you can't disable the security dialogs that pop
up when an application tries to access certain Outlook properties and
methods. See http://www.slipstick.com/outlook/esecup.htm#autosec
If you're the administrator in an Exchange Server or HP OpenMail
environment, you can reduce the impact of the security prompts with
administrative tools. See http://www.slipstick.com/outlook/esecup/admin.htm.
Since it's an application you wrote yourself, you can use one of these two
approaches to redo the program:
-- Use Extended MAPI (see http://www.slipstick.com/dev/mapi.htm) and C++
or Delphi
-- Use Redemption (http://www.dimastr.com/redemption/)
--
Sue Mosher, Outlook MVP
Author of
Teach Yourself Microsoft Outlook 2000 Programming in 24 Hours
Microsoft Outlook 2000 E-mail and Fax Guide
Outlook and Exchange solutions at http://www.slipstick.com
"Jackson" <lcseng@hotmail.com> wrote in message
news:0f8201c13244$c98472b0$95e62ecf@tkmsftngxs02...
> How can I set up security in outlook to allow my code to
> execute item.send without popping up a warning message?
>
> I am trying to set up my application to send an email to
> an admin. when my app. is successfully executed.
**********************************************************************