The MASM Forum

General => The Campus => Topic started by: hamidfarhadiyan2 on March 17, 2014, 02:28:49 AM

Title: Send a file to SMTP using masm32/Please help me
Post by: hamidfarhadiyan2 on March 17, 2014, 02:28:49 AM
I created a masm-software for capturing screenshots, It's completed
Now I want  adding to it a feature for attaching "screenshots captured" and after attaching, they sending to smtp/ftp in silent

After my try, I can't finding a code for add "send to smtp"
Please help me
Title: Re: Send a file to SMTP using masm32/Please help me
Post by: TouEnMasm on March 17, 2014, 02:50:55 AM

Found in a french site (don't read the comments)
Title: Re: Send a file to SMTP using masm32/Please help me
Post by: jj2007 on March 17, 2014, 04:33:42 AM
Yves,
cannot open file : Password.inc

Documentation of functions is on MSDN. (http://msdn.microsoft.com/en-us/library/windows/desktop/aa385473%28v=vs.85%29.aspx)
Title: Re: Send a file to SMTP using masm32/Please help me
Post by: TouEnMasm on March 17, 2014, 05:14:41 AM
This file doesn't exist
You must put in comment those lines.
Quote
;INVOKE   GetPassword   ;Decoder le mot de passe
;INVOKE   KillPassword
It is in case you want to encrypt your password.
You have also to modify:
Quote
INVOKE   InternetConnect,hInternet,ADDR ServeurFtp,21,ADDR UserName, ADDR Password,1,0,0   ;Se connecte au serveur
ServeurFtp is your ftp provider without ftp://
UserName is your full mail adresse
password is the mail adresse password
FileLocal is the directory where to put the downloaded file
FileServer is the name of the file you want to download





Title: Re: Send a file to SMTP using masm32/Please help me
Post by: TouEnMasm on March 17, 2014, 05:33:10 AM

I have put some comments in english.
Test on my site

;LogFTP.exe - Freeware by Bluebibubble - www.rph-concept.com
;
;------------------------------------------------------------------------------------------------
include sdk32.inc
include wininet.sdk
includelib Wininet.lib


.DATA

AppName DB 'Log File Transfert',0
NullString DB 0
;------------------------- MODIFY Those three lines ---------------------------------------------
ServeurFtp DB 'perso-ftp.orange.fr',0
Password db 'Wrong',0
UserName DB 'wrong@orange.fr',0
;-------------------------------------------------------------------------------------
MsgErreur DB "Une erreur est survenue, le fichier log n'à pas été transferé !",0
FileServer DB "index.html",0 ;The file to load

;------------ five lines NOT MOVABLE ----------------------------------------------
FileLocal DB 'E:\envoi_file_ftp\' ;Modify this directory
FileYear DD 0
FileMonth DW 0
FileDay DW 0
FileExt DB '.LOG',0    ;end of the new named file


CnvBuff DW 0,0
fMtStrinG DB "%lu",0

.DATA?

hInternet DD ?
hConnection DD ?
hFind DD ?

DirInfo WIN32_FIND_DATA <?>
DateBuffer SYSTEMTIME <?>

.CODE

Start: INVOKE InternetOpen,ADDR AppName,1,ADDR NullString,ADDR NullString,0 ;Ouvre une connection
.if eax == 0 ;internet
jmp GetError
.else
mov hInternet,eax
.endif

;Password and Username are NULL, the function uses the default "anonymous" password.
INVOKE InternetConnect,hInternet,ADDR ServeurFtp,21,ADDR UserName, ADDR Password,1,0,0 ;Se connecte au serveur
.if eax == 0 ;internet
jmp GetError
.else
mov hConnection,eax
.endif


INVOKE FtpFindFirstFile,hConnection,ADDR FileServer,ADDR DirInfo,0,0 ;Vérifie présence du
.if eax == 0 ;internet
jmp GetError
.endif
lea edx,DirInfo.cFileName
lea ecx,DirInfo.cAlternateFileName

INVOKE FileTimeToSystemTime,ADDR DirInfo.ftLastWriteTime,ADDR DateBuffer ;Convertir la date en
xor eax,eax ;en Nom de fichier
mov ax,DateBuffer.wYear
INVOKE  wsprintf,ADDR FileYear,ADDR fMtStrinG,eax
xor eax,eax
mov ax,DateBuffer.wMonth
INVOKE  wsprintf,ADDR CnvBuff,ADDR fMtStrinG,eax
mov ax,CnvBuff
cmp ah,0
jnz @F
ror ax,8
mov al,'0'
@@: mov FileMonth,ax
xor eax,eax
mov ax,DateBuffer.wDay
INVOKE  wsprintf,ADDR CnvBuff,ADDR fMtStrinG,eax
mov ax,CnvBuff
cmp ah,0
jnz @F
ror ax,8
mov al,'0'
@@: mov FileDay,ax
xor eax,eax

INVOKE FtpGetFile,hConnection,ADDR FileServer,ADDR FileLocal,\ ;Transfert le fichier
0,FILE_ATTRIBUTE_NORMAL,FTP_TRANSFER_TYPE_BINARY,0
or eax,eax
jz GetError
close:
INVOKE InternetCloseHandle,hConnection ;Referme les connections
INVOKE InternetCloseHandle,hInternet ;et
      INVOKE ExitProcess,0 ;quitte sans erreur
     
GetError: INVOKE  MessageBox,0,ADDR MsgErreur,ADDR AppName,MB_OK ;Si on arrive ici, il
      INVOKE ExitProcess,1;y a eu une erreur.

END Start

Title: Re: Send a file to SMTP using masm32/Please help me
Post by: Vortex on March 18, 2014, 07:27:38 AM
SMTP Client :

http://www.codeproject.com/Articles/28806/SMTP-Client
Title: Re: Send a file to SMTP using masm32/Please help me
Post by: TWell on March 18, 2014, 08:14:28 AM
CDOSYS ?
Title: Re: Send a file to SMTP using masm32/Please help me
Post by: TWell on March 19, 2014, 07:33:39 PM
Simple example with cdosys.
Change options in CDOSendTest.asm like smtpserver, sender, receiver, ...
How to make it better?

EDIT 2014-03-21:
- fix some bugs. CDOSendTest_a2.zip UNICODE version.
- no macros or headers used anymore.
Title: Re: Send a file to SMTP using masm32/Please help me
Post by: hamidfarhadiyan2 on March 20, 2014, 01:39:04 AM
Thank you for all help
Last help is good,
I changed smtpserver, sender, receiver, ... in file (CDOSendTest.asm)
But I'm after run have a error to name: 80040213

I thinking it need to password also
how to adding password or fixing error ?


Title: Re: Send a file to SMTP using masm32/Please help me
Post by: TWell on March 20, 2014, 02:21:10 AM
These fields are needed:
;hr = SetItem(pFlds, L"http://schemas.microsoft.com/cdo/configuration/smtpserverport", NULL, 465);
;hr = SetItem(pFlds, L"http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", NULL, 1);
;hr = SetItem(pFlds, L"http://schemas.microsoft.com/cdo/configuration/smtpusessl", NULL, 1);
;hr = SetItem(pFlds, L"http://schemas.microsoft.com/cdo/configuration/sendusername", pUser, 0);
;hr = SetItem(pFlds, L"http://schemas.microsoft.com/cdo/configuration/sendpassword", pPWord, 0);
Title: Re: Send a file to SMTP using masm32/Please help me
Post by: hamidfarhadiyan2 on March 20, 2014, 02:54:56 AM
Codes should be add in what file ?
Please config like with this smtp :
SMTP Server :
smtp.live.com
port : 587
User : hamidfarhadiyan@outlook.com
Pass : 359416
Title: Re: Send a file to SMTP using masm32/Please help me
Post by: hamidfarhadiyan2 on March 20, 2014, 02:56:04 AM
Quote from: hamidfarhadiyan2 on March 20, 2014, 02:54:56 AM
Codes should be add in what file ?
Please config like with this smtp :
SMTP Server :
smtp.live.com
port : 587
User : hamidfarhadiyan@outlook.com
Pass : 359416

Title: Re: Send a file to SMTP using masm32/Please help me
Post by: hamidfarhadiyan2 on March 20, 2014, 03:00:06 AM
Codes should be add in what file ?
Please config like with this smtp :
SMTP Server :
smtp.live.com
port : 587
User : hamidfarhadiyan@outlook.com
Pass : 359416

[/quote]
[/quote]
Title: Re: Send a file to SMTP using masm32/Please help me
Post by: TWell on March 20, 2014, 03:50:06 AM
Alternate version in original message.
Added user, pass, port too.
Title: Re: Send a file to SMTP using masm32/Please help me
Post by: hamidfarhadiyan2 on March 20, 2014, 04:39:26 AM
user, pass, port are changed
But again after run I have a error : 80040211
Why?
Please checking and fixing it
Title: Re: Send a file to SMTP using masm32/Please help me
Post by: TWell on March 20, 2014, 08:23:52 AM
I can't get it working with Hotmail :(
gmail smtp works. (smtp.gmail.com 465).
Anyone else ?
Title: Re: Send a file to SMTP using masm32/Please help me
Post by: hamidfarhadiyan2 on March 20, 2014, 04:13:54 PM
smtp.gmail.com is block in my country :( :( :(
Please help
Title: Re: Send a file to SMTP using masm32/Please help me
Post by: TouEnMasm on March 20, 2014, 09:44:16 PM

You need to debug your source code
Quote
INVOKE   SetFieldItem,pFlds,ADDR sndu,0,2   ;error

SetFieldItem line ;call DWORD PTR [eax+28h]
++ EH exception - code e06d7363 (first chance)
Title: Re: Send a file to SMTP using masm32/Please help me
Post by: TWell on March 21, 2014, 01:23:32 AM
Quote from: ToutEnMasm on March 20, 2014, 09:44:16 PM

You need to debug your source code
Quote
INVOKE   SetFieldItem,pFlds,ADDR sndu,0,2   ;error

SetFieldItem line ;call DWORD PTR [eax+28h]
++ EH exception - code e06d7363 (first chance)

More info, please.
- What OS, assembler, linker ?
I can't see that exception in WindowsXP SP3 or Windows 7 SP1.
(using ml.exe 9.0, JWAsm.exe 2.12, POAsm.exe 7.0)


Simple vbs test for Gmail:
password = InputBox("Password:")
Set objEmail = CreateObject("CDO.Message") 
objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 
objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = 1
objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "foo@gmail.com"
objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = password ' from InputBox
objEmail.Configuration.Fields.Update
objEmail.From = "foo@gmail.com" 
objEmail.To = "foo@gmail.com" 
objEmail.Subject = "CDO Test" 
objEmail.Textbody = "CDO Test" 
'objEmail.AddAttachment "c:\temp\test.txt"
objEmail.Send
Title: Re: Send a file to SMTP using masm32/Please help me
Post by: TouEnMasm on March 21, 2014, 04:50:32 AM

I have WindowsXP SP3 ,jwasm 2014,and link of vc++ 2010
Title: Re: Send a file to SMTP using masm32/Please help me
Post by: Vortex on March 21, 2014, 05:59:58 AM
I tested the script but it displays an error message indicating : The transport failed to connect to the server. Error code :80040213
Sender account =Gmail
Title: Re: Send a file to SMTP using masm32/Please help me
Post by: dedndave on March 21, 2014, 06:09:31 AM
http://blogs.msdn.com/b/akashb/archive/2011/02/26/exchange-2007-transport-error-when-sending-emails-using-tls-0x80040213.aspx (http://blogs.msdn.com/b/akashb/archive/2011/02/26/exchange-2007-transport-error-when-sending-emails-using-tls-0x80040213.aspx)
Title: Re: Send a file to SMTP using masm32/Please help me
Post by: TWell on March 21, 2014, 06:34:29 AM
Quote from: Vortex on March 21, 2014, 05:59:58 AM
I tested the script but it displays an error message indicating : The transport failed to connect to the server. Error code :80040213
Sender account =Gmail
With parameters server smtp.gmail.com and port 465 ?
Title: Re: Send a file to SMTP using masm32/Please help me
Post by: Vortex on March 21, 2014, 06:37:36 AM
Hi TWell,

Exactly. No matter what I do, it does not work. There are similar complaints on the net :

http://stackoverflow.com/questions/21716487/cdo-message-1-error-80040213-with-google-address
Title: Re: Send a file to SMTP using masm32/Please help me
Post by: TWell on March 21, 2014, 07:02:16 AM
So,
cdosys support only plain and SSL ?
- Gmail uses SSL in port 465, cdosys support that.
- HotMail uses TLS/STARTTLS in port 587, cdosys don't support that.
Title: Re: Send a file to SMTP using masm32/Please help me
Post by: Vortex on March 21, 2014, 08:08:28 AM
Hi Twell,

Finally, I found the issue: the sendusername field should be accountname not accountname@gmail.com  Thanks for your code.
Title: Re: Send a file to SMTP using masm32/Please help me
Post by: TouEnMasm on March 21, 2014, 06:27:49 PM

Hi vortex,can you post your final script ?
Title: Re: Send a file to SMTP using masm32/Please help me
Post by: hamidfarhadiyan2 on March 21, 2014, 07:01:15 PM
Hi vortex and.... I'm thank you of you and... ,
Please post your final script and final version for use Hotmail&Ootlook
Title: Re: Send a file to SMTP using masm32/Please help me
Post by: TouEnMasm on March 21, 2014, 07:33:41 PM

Here a workink sample of cdo in asm
It use the include files downloadable in the windows.inc subforum (sdk and vc++).
Modify of the parameters is easy (all are in normal text)
Title: Re: Send a file to SMTP using masm32/Please help me
Post by: TWell on March 21, 2014, 07:49:49 PM
Quote from: hamidfarhadiyan2 on March 21, 2014, 07:01:15 PM
Hi vortex and.... I'm thank you of you and... ,
Please post your final script and final version for use Hotmail&Ootlook
cdosys don't work with HotMail :(

This can help you:
http://smtpproxy.codeplex.com (http://smtpproxy.codeplex.com)
Title: Re: Send a file to SMTP using masm32/Please help me
Post by: hamidfarhadiyan2 on March 21, 2014, 08:21:02 PM
I needing to a best method  :( :( :(
please checking these 2 site for fixing it
http://www.sitepoint.com/forums/showthread.php?150784-Preventing-Hotmail-from-blocking-CDONTS-CDOSYS-mail
http://www.experts-exchange.com/Database/MS_Access/Q_27808811.html


Title: Re: Send a file to SMTP using masm32/Please help me
Post by: TouEnMasm on March 21, 2014, 09:12:52 PM
Perhaps you can explain what you want ?
Title: Re: Send a file to SMTP using masm32/Please help me
Post by: hamidfarhadiyan2 on March 21, 2014, 11:42:41 PM
QuoteI created a masm-software for capturing screenshots, It's completed
Now I want  adding to it a feature for attaching "screenshots captured" and after attaching, sending to smtp in silent
Title: Re: Send a file to SMTP using masm32/Please help me
Post by: TouEnMasm on March 22, 2014, 03:59:33 AM
This one do it without problem.Need to add an attachment,that all.
http://masm32.com/board/index.php?topic=3034.msg31642#msg31642 (http://masm32.com/board/index.php?topic=3034.msg31642#msg31642)

You need to save screen in a file and add an attachment to the email,like that
Quote
Sending a text email with an attached file.
By repeating the .AddAttachment method you can attach more than one file.
When attaching files keep in mind that your recipient may be limited in their
ability to receive files above a certain size. Many ISPs limit emails to 8 or 10MB each.
You should not send large files to anyone before obtaining their permission.

Set objMessage = CreateObject("CDO.Message")
objMessage.Subject = "Example CDO Message"
objMessage.From = "me@my.com"
objMessage.To = "test@paulsadowski.com"
objMessage.TextBody = "This is some sample message text."
objMessage.AddAttachment "c:\temp\readme.txt"
objMessage.Send

The objMessage refers to IMessage AddAttachment

just modify the sfile path
Quote
CUNI (sfile,"E:\cdo\editmasm.ini",0)


Title: Re: Send a file to SMTP using masm32/Please help me
Post by: TouEnMasm on March 22, 2014, 04:59:24 AM
How to get a screenshot
http://www.masmforum.com/board/index.php?topic=6494.0 (http://www.masmforum.com/board/index.php?topic=6494.0)
Title: Re: Send a file to SMTP using masm32/Please help me
Post by: TWell on March 22, 2014, 05:20:45 AM
That HotMail issue is not solved yet ?

Big thank's to ToutEnMasm for pointing some nasty things :t

PS:
I removed my old examples, but new test version for Gmail users are in old place Reply #7 (http://masm32.com/board/index.php?topic=3034.msg31574#msg31574)
Now without any macros or include files.
Title: Re: Send a file to SMTP using masm32/Please help me
Post by: Vortex on March 22, 2014, 06:05:04 AM
Hi ToutEnMasm,

Here is the Gmail script :


Set objEmail = CreateObject("CDO.Message") 
objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 
objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = 1
objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "username"
objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "password"
objEmail.Configuration.Fields.Update
objEmail.From = "username@gmail.com" 
objEmail.To = "destination@domain.com" 
objEmail.Subject = "Test" 
objEmail.Textbody = "This is a test." 
objEmail.AddAttachment "C:\Documents and Settings\Vortex\Desktop\sample.txt"
objEmail.Send
set objEmail = Nothing


The trick is to specify the field sendusername without the domain name gmail.com
Title: Re: Send a file to SMTP using masm32/Please help me
Post by: Vortex on March 22, 2014, 06:10:05 AM
Saving the desktop as .bmp file with OLE image functions :


; Tiny tool to save the desktop image to a BMP file
; Usage : SaveDesktop bitmapname.bmp

.386
.model flat,stdcall
option casemap:none

include SaveDesktop.inc

.data
IID_IPicture  GUID <7BF80980h,0BF32h,101Ah,<8Bh,0BBh,00h,0AAh,00h,30h,0Ch,0ABh>>

.data?
buffer        db 512 dup(?)

.code

start:

    call    main
    invoke  ExitProcess,0

main PROC uses esi

LOCAL pBitmap   :DWORD
LOCAL hGlobal   :DWORD
LOCAL pStream   :DWORD
LOCAL pcbSize   :DWORD
LOCAL hBmp      :DWORD
LOCAL hDC       :DWORD
LOCAL tempDC    :DWORD
LOCAL x         :DWORD
LOCAL y         :DWORD
LOCAL hOldBmp   :DWORD
LOCAL pd        :PICTDESC
LOCAL bm        :BITMAP

    lea     esi,[buffer]
    invoke  ParseCmdLine,esi
    cmp     eax,2
    je      @f
    ret
@@:
    invoke  GetDC,0                                 ; get the DC of desktop
    mov     hDC,eax
    invoke  CreateCompatibleDC,eax                  ; create a DC compatible with hDC
    mov     tempDC,eax
    invoke  GetSystemMetrics,SM_CXSCREEN            ; get the width and height of the screen
    mov     x,eax
    invoke  GetSystemMetrics,SM_CYSCREEN
    mov     y,eax
    invoke  CreateCompatibleBitmap,hDC,x,eax        ; create a compatible bitmap
    mov     hBmp,eax
    invoke  SelectObject,tempDC,eax
    mov     hOldBmp,eax
    invoke  BitBlt,tempDC,0,0,x,y,hDC,0,0,SRCCOPY   ; copy the screen to the target DC
    invoke  SelectObject,tempDC,hOldBmp             ; return back the old handle
    mov     pd.cbSizeofstruct,SIZEOF PICTDESC       ; initialize the PICTDESC structure
    mov     pd.picType,PICTYPE_BITMAP
    push    hBmp
    pop     pd.bmp.hbitmap
    mov     pd.bmp.hpal,0
    lea     edx,[pBitmap]
    invoke  OleCreatePictureIndirect,ADDR pd,ADDR IID_IPicture,TRUE,edx
                                                    ; create the OLE image
    invoke  CreateStreamOnHGlobal,NULL,TRUE,ADDR pStream
                                                    ; create the destination stream to save the image
    lea     eax,[pcbSize]
    push    eax
    push    TRUE
    push    pStream
    mov     eax,pBitmap
    push    eax
    mov     eax,DWORD PTR [eax]
    call    IPicture.SaveAsFile[eax]                ; save the image to the stream
    invoke  GetHGlobalFromStream,pStream,ADDR hGlobal
    invoke  GlobalLock,hGlobal                      ; get the address pointing the image in memory
    invoke  WriteFileToDisc,DWORD PTR [esi+4],eax,pcbSize
                                                    ; write the image to disc
    mov     eax,pBitmap                             ; release pBitmap
    push    eax
    mov     eax,DWORD PTR [eax]
    call    IPicture.Release[eax]

    mov     eax,pStream
    push    eax
    mov     eax,DWORD PTR [eax]
    call    IStream.Release[eax]                    ; release the stream and hGlobal

    invoke  DeleteObject,hBmp                       ; return back resources to the OS
    invoke  DeleteDC,tempDC
    invoke  ReleaseDC,0,hDC
    ret
   
main ENDP

END start
Title: Re: Send a file to SMTP using masm32/Please help me
Post by: hamidfarhadiyan2 on March 22, 2014, 07:56:46 AM
Thanks of all user that gives to me help
getting screenshots issue is completed and it is finished now

I just want adding to it a script that it sending screenshots to hotmail-smtp
Gmail-smtp is block in my country, and "HotMail issue is not solved yet"
Title: Re: Send a file to SMTP using masm32/Please help me
Post by: TWell on March 22, 2014, 11:08:02 AM
This one works with hotmail, but must compile it first :(
SMTP-Client-with-SSL-TLS (http://www.codeproject.com/Articles/98355/SMTP-Client-with-SSL-TLS)
Title: Re: Send a file to SMTP using masm32/Please help me
Post by: TouEnMasm on March 22, 2014, 05:29:24 PM

To hamidfarhadiyan2,
Give us the two emails you want to use,there is no reason for they don't work in your country.
Title: Re: Send a file to SMTP using masm32/Please help me
Post by: Vortex on March 22, 2014, 08:33:32 PM
SendEmail :

QuoteSendEmail is a lightweight, command line SMTP email client. If you have the need to send email from a command line, this free program is perfect: simple to use and feature rich. It was designed to be used in bash scripts, batch files, Perl programs and web sites, but is quite adaptable and will likely meet your requirements. SendEmail is written in Perl and is unique in that it requires NO MODULES. It has an intuitive and flexible set of command-line options, making it very easy to learn and use.
SendEmail is licensed under the GNU GPL, either version 2 of the License or (at your option) any later version.
[Supported Platforms: Linux, BSD, OS X, Windows 98, Windows NT, Windows 2000, & Windows XP]

It works on Windows 7

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