Mail-Lib - E-Mail versenden

Für allgemeine Fragen zur Programmierung mit PureBasic.
Benutzeravatar
ts-soft
Beiträge: 22292
Registriert: 08.09.2004 00:57
Computerausstattung: Mainboard: MSI 970A-G43
CPU: AMD FX-6300 Six-Core Processor
GraKa: GeForce GTX 750 Ti, 2 GB
Memory: 16 GB DDR3-1600 - Dual Channel
Wohnort: Berlin

Re: Mail-Lib - E-Mail versenden

Beitrag von ts-soft »

Mit einer fixen FileID in einer Userlib, typisch Droopy... :mrgreen:

Mal sehen, wenn alles klappt werde ich morgen eine überarbeitete Version in der Tipps & Trickssektion posten.
Linux und Unicode sollten dann auch unterstützt werden, hoffe ich mal. Aber vor dem Release muss ich noch
etwas Gehirnschmalz investieren :mrgreen:

Gruß
Thomas
PureBasic 5.73 LTS | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Nutella hat nur sehr wenig Vitamine. Deswegen muss man davon relativ viel essen.
Bild
Nino
Beiträge: 1300
Registriert: 13.05.2010 09:26
Wohnort: Berlin

Re: Mail-Lib - E-Mail versenden

Beitrag von Nino »

Ich denke, in diesem Zusammenhang ist auch folgendes Projekt von cptdark
http://forums.purebasic.com/german/view ... =8&t=23313
erwähnenswert.

Grüße, Nino
Velz
Beiträge: 182
Registriert: 18.10.2004 22:20

Re: Mail-Lib - E-Mail versenden

Beitrag von Velz »

ts-soft hat zwar schon eine Lösung gebaut, aber anbei der Link zu einem Tool das ich für den Mailversand mit auth verwende.

http://caspian.dotconf.net/menu/Software/SendEmail/

Das ist einfach ein Kommandozeilenprogramm dem ich Parameter übergebe. Gibt es für Linux und Windows.
Win10/64|Ubuntu-Server|Mint WS // Programmiere Datenbankanwendungen und Tools mit PB-5.x und MySQL-5.x unter Win und Linux
Benutzeravatar
bobobo
jaAdmin
Beiträge: 3873
Registriert: 13.09.2004 17:48
Kontaktdaten:

Re: Mail-Lib - E-Mail versenden

Beitrag von bobobo »

kunstlust hat geschrieben:@TS-Soft
Es ist schon schade, das diese "Grundfunktion" in PB nicht drin ist, welcher Mailserver nimmt noch Mails ohne "SMTP-Auth" an.
[/code]
Es gibt durchaus lokale MailServer (*)(da fällt mir mal hMailServer zu ein)
die den Versand (und auch den Enpfang) für Dich erledigen können und
damit lässt sich prima mit PB kommunizieren über die
Pb-internen Spar-Mail-Möglichkeiten :)

(*) Das soll keine Empfehlung für den Normaluser sein. Ein Mailserver ist nicht ganz ohne
und lockt Ungeziefer an, wenn man den und das Umfeld falsch konfiguriert.
‮pb aktuel 6.2 windoof aktuell und sowas von 10
Ich hab Tinnitus im Auge. Ich seh nur Pfeifen.
Benutzeravatar
kunstlust
Beiträge: 259
Registriert: 12.04.2012 23:47
Wohnort: Hannover
Kontaktdaten:

Re: Mail-Lib - E-Mail versenden

Beitrag von kunstlust »

ich habe mal versucht das aus dem VBS http://www.paulsadowski.com/wsh/cdo.htm zu übernehmen, was mir aber nicht gelingt:

Code: Alles auswählen

XIncludeFile "COMatePLUS.pbi"

 objMessage.COMateObject
 objConfiguration.COMateObject


 objMessage = COMate_CreateObject("CDO.Message")
objConfiguration = COMate_CreateObject("CDO.Configuration")

If objMessage
  
  objMessage\GetStringProperty("Subject='Example CDO Message'")
  objMessage\GetStringProperty("From='postmaster@test.de'")
  objMessage\GetStringProperty("To='monster@ag.de'")
  objMessage\GetStringProperty("HTMLBody='<h1>This is some sample message html.</h1>'")
  ;objMessage\SetStringProperty("Bcc='you@your.com'")
  ;objMessage\SetStringProperty("Cc='you2@your.com'")
 
  objConfiguration\SetProperty ("Configuration\Fields\Item"+Chr(40)+"http://schemas.microsoft.com/cdo/configuration/sendusing"+Chr(41)+Chr(61) +"1"+Chr(41))
objConfiguration\SetProperty ("Configuration\Fields\Item"+Chr(40)+"http://schemas.microsoft.com/cdo/configuration/smtpserver"+Chr(41)+Chr(61) +"mail.mailserver.de"+Chr(41))
objConfiguration\SetProperty ("Configuration\Fields\Item"+Chr(40)+"http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"+Chr(41)+Chr(61) +"cdoBasic"+Chr(41))
objConfiguration\SetProperty ("Configuration\Fields\Item"+Chr(40)+"http://schemas.microsoft.com/cdo/configuration/sendusername"+Chr(41)+Chr(61) +"hamster@rad.de"+Chr(41))
objConfiguration\SetProperty ("Configuration\Fields\Item"+Chr(40)+"http://schemas.microsoft.com/cdo/configuration/sendpassword"+Chr(41)+Chr(61) +"password"+Chr(41))
objConfiguration\SetProperty ("Configuration\Fields\Item"+Chr(40)+"http://schemas.microsoft.com/cdo/configuration/smtpserverport"+Chr(41)+Chr(61) +"25"+Chr(41))
objConfiguration\SetProperty ("Configuration\Fields\Item"+Chr(40)+"http://schemas.microsoft.com/cdo/configuration/smtpusessl"+Chr(41)+Chr(61) +"True"+Chr(41))
objConfiguration\SetProperty ("Configuration\Fields\Item"+Chr(40)+"http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout"+Chr(41)+Chr(61) +"60"+Chr(41))
  
 objConfiguration\SetProperty("Configuration\Fields\Update")
  
objMessage\invoke("Send")




  Debug COMate_GetLastErrorDescription() 
  objMessage\Release()
EndIf
Irgenwie komme ich mit dem Zeichensetzen durcheinander.... Die Meldung ist immer "Der "SendUsing"-Konfigurationswert ist ungültig."
Aber der Ansatz könnte zu mindestens unter Windows helfen
Benutzeravatar
NicTheQuick
Ein Admin
Beiträge: 8807
Registriert: 29.08.2004 20:20
Computerausstattung: Ryzen 7 5800X, 64 GB DDR4-3200
Ubuntu 24.04.2 LTS
GeForce RTX 3080 Ti
Wohnort: Saarbrücken

Re: Mail-Lib - E-Mail versenden

Beitrag von NicTheQuick »

Ich hab damit noch nie was gemacht, aber sollte das nicht so heißen?

Code: Alles auswählen

objConfiguration\SetProperty("Configuration\Fields\Item(" + Chr(34) + "http://schemas.microsoft.com/cdo/configuration/sendusing" + Chr(34) + ")=1")
Das erscheint mir logischer. Zumal ich auch nicht verstehe, warum du die Klammern und das Gleichheitszeichen überhaupt mit Chr() kodiert hast.
Benutzeravatar
Kiffi
Beiträge: 10711
Registriert: 08.09.2004 08:21
Wohnort: Amphibios 9

Re: Mail-Lib - E-Mail versenden

Beitrag von Kiffi »

außerdem bringst Du GetStringProperty() und SetStringProperty()
durcheinander.

... und Fields\Update scheint mir eine Methode zu sein, die dann mit
Invoke() aufgerufen werden sollte.

Grüße ... Kiffi
a²+b²=mc²
Benutzeravatar
kunstlust
Beiträge: 259
Registriert: 12.04.2012 23:47
Wohnort: Hannover
Kontaktdaten:

Re: Mail-Lib - E-Mail versenden

Beitrag von kunstlust »

Ich habe es für meine Bedürfnisse gekürzt http://forum.purebasic.com/english/view ... p?p=266648
Kern der Geschichte ist aber die nicht immer ganz einfache Schreibweise. :wink:

Code: Alles auswählen

XIncludeFile "COMatePLUS.pbi"
Define.COMateObject objemail,iconf,objbodypart,objbodypart1
objemail = COMate_CreateObject("CDO.Message") 
iConf = COMate_CreateObject("CDO.Configuration")

ToAddress.s ="pb@mailserver.de"
SmtpServer.s = "mail.mailserver.de"
FromName.s="PB Mailtest"
FromAddress.s ="postmaster@mailserver.de"
replyto.s =""
Subject.s ="Test"
BodyHTML.s ="<h1>Ich bin eine Bodytext</h1>"
SmtpServer.s ="mein.mailserver.de"

Username.s="postmaster@mailserver.de"
Password.s="Geheim"
CcAddress.s
BccAddress.s

If objemail
  objemail\SetProperty("Configuration="+ Str(iconf)+ " As COMateObject"  ) 
  objemail\SetProperty("MimeFormatted=1" ) 
  objemail\SetProperty("to='"+ ToAddress +"'") 
  objemail\SetProperty("from='"+Chr(34)+ FromName + Chr(34)+  "<" + FromAddress + ">" +"'")
  objemail\SetProperty("Subject='"+Subject+"'") 
  objemail\SetProperty(" HTMLBody="+"'"+BodyHTML+"'") 
  objemail\SetProperty("replyTo ='"+replyto+"'") 
  If CcAddress <> "" 
    objemail\SetProperty("Cc ='"+ CcAddress +"'") 
  EndIf 
  If BccAddress <> "" 
    objemail\SetProperty("Bcc ='"+ BccAddress +"'") 
  EndIf
  objemail\SetProperty("Configuration\Fields\Item ('http://schemas.microsoft.com/cdo/configuration/sendusing') = 2" )
  objemail\SetProperty("Configuration\Fields\Item ('http://schemas.microsoft.com/cdo/configuration/smtpserver') =" +"'"+ SmtpServer+"'" ) 
  If IPPort = 0
    IPPort = 25
  EndIf 
  objemail\SetProperty("Configuration\Fields\Item ('http://schemas.microsoft.com/cdo/configuration/smtpserverport') ="+ Str(IPPort))
  If Username <> "" 
    objemail\SetProperty("Configuration\Fields\Item ('http://schemas.microsoft.com/cdo/configuration/smtpauthenticate') =1")
    objemail\SetProperty("Configuration\Fields\Item ('http://schemas.microsoft.com/cdo/configuration/sendusername') ="+ "'"+ Username+"'")
    objemail\SetProperty("Configuration\Fields\Item ('http://schemas.microsoft.com/cdo/configuration/sendpassword') =" +"'"+ Password +"'" )
  EndIf
  If ssl 
    objemail\SetProperty("Configuration\Fields\Item ('http://schemas.microsoft.com/cdo/configuration/smtpusessl') = 2" )
  EndIf
  objemail\SetProperty("Configuration\Fields\Item ('http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout') = 60")
     objemail\Invoke("Configuration\Fields\Update")
objemail\invoke("Send")
  Debug COMate_GetLastErrorDescription() 
  objemail\Release()
EndIf
Benutzeravatar
kunstlust
Beiträge: 259
Registriert: 12.04.2012 23:47
Wohnort: Hannover
Kontaktdaten:

Re: Mail-Lib - E-Mail versenden

Beitrag von kunstlust »

Hallo,

ich habe ein Problem mit dem Anhängen einer Datei, da ich nur unter Windows mailen möchte und Strato nun auf SSL umstellt, bin ich noch mal auf die CDO Methode gekommen, die Grundlage dafür ist auf folgender Seite zu finden http://www.paulsadowski.com/wsh/cdo.htm. Soweit mir bekannt ist SSL in SendMail() von PB noch nicht möglich, ich habe noch ein paar andere Dinge probiert die in den Foren mit der cryptlib.dll laufen sollte, aber der Erfolg war mir nicht geben. Ich nutze die aktuelle PB 5.21 LTS.
Ohne Dateianhang läuft die Methode ja auch und ist ohne viel Aufwand, aber ein Attachment per 'objMessage.AddAttachment "c:\temp\readme.txt"' anzuhängen, klappt nicht :-(

Hat jemand eine Idee woran es liegt?

Code: Alles auswählen

XIncludeFile "COMatePLUS.pbi"
Define.COMateObject objemail,iconf,objbodypart,objbodypart1
objemail = COMate_CreateObject("CDO.Message")
iConf = COMate_CreateObject("CDO.Configuration")

ToAddress.s ="an@mail.de"
SmtpServer.s = "smtp.strato.de"
FromName.s="PB Mailtest "
FromAddress.s ="von@mail.de"
replyto.s ="replay@mail.de"
Subject.s ="Testmail per CDO"
BodyHTML.s ="<h2>Ich bin der Bodytext</h2>"
IPPort.i = 465
ssl.b = 1
timeout.i = 60
Attachment.s = "c:\test.txt" 
Username.s="username"
Password.s="passwort"


CcAddress.s
BccAddress.s


If objemail
  
  objemail\SetProperty("Configuration="+ Str(iconf)+ " As COMateObject"  )
  objemail\SetProperty("MimeFormatted=1" )
  objemail\SetProperty("to='"+ ToAddress +"'")
  objemail\SetProperty("from='"+Chr(34)+ FromName + Chr(34)+  "<" + FromAddress + ">" +"'")
  objemail\SetProperty("Subject='"+Subject+"'")
  objemail\SetProperty("HTMLBody="+"'"+BodyHTML+"'")
  objemail\SetProperty("replyTo ='"+replyto+"'")
  objemail\SetProperty("AddAttachment"+Chr(34)+Attachment+Chr(34)); eigentlich sollte das so OK sein, es kommt aber nichts an....
  If CcAddress <> ""
    objemail\SetProperty("Cc ='"+ CcAddress +"'")
  EndIf
  If BccAddress <> ""
    objemail\SetProperty("Bcc ='"+ BccAddress +"'")
  EndIf
  objemail\SetProperty("Configuration\Fields\Item ('http://schemas.microsoft.com/cdo/configuration/sendusing') = 2" )
  objemail\SetProperty("Configuration\Fields\Item ('http://schemas.microsoft.com/cdo/configuration/smtpserver') =" +"'"+ SmtpServer+"'" )
  objemail\SetProperty("Configuration\Fields\Item ('http://schemas.microsoft.com/cdo/configuration/smtpserverport') ="+IPPort)
  objemail\SetProperty("Configuration\Fields\Item ('http://schemas.microsoft.com/cdo/configuration/smtpauthenticate') =1")
  objemail\SetProperty("Configuration\Fields\Item ('http://schemas.microsoft.com/cdo/configuration/sendusername') ="+ "'"+ Username+"'")
  objemail\SetProperty("Configuration\Fields\Item ('http://schemas.microsoft.com/cdo/configuration/sendpassword') =" +"'"+ Password +"'" )
  objemail\SetProperty("Configuration\Fields\Item ('http://schemas.microsoft.com/cdo/configuration/smtpusessl') ="+ssl)
  objemail\SetProperty("Configuration\Fields\Item ('http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout') ="+timeout)
  Delay(50)
  objemail\Invoke("Configuration\Fields\Update")
  objemail\invoke("Send")
  Debug COMate_GetLastErrorDescription()
  objemail\Release()
EndIf
Benutzeravatar
bobobo
jaAdmin
Beiträge: 3873
Registriert: 13.09.2004 17:48
Kontaktdaten:

Re: Mail-Lib - E-Mail versenden

Beitrag von bobobo »

Keine Idee

Aaaber .. ich habe relativ oft Erfolg (*)mit dem Mailversand per SSL
wenn ich die "normale" Sendmail.lib von PB (ab 5.1 , die mit Auth-Unterstützung)
benutze und das per stunnel weiterleite.

(*) 1und1 und gmx geht, t-online und g4w , wenn man in der stunnel-Konfig das protocol smtp mit angibt
‮pb aktuel 6.2 windoof aktuell und sowas von 10
Ich hab Tinnitus im Auge. Ich seh nur Pfeifen.
Antworten