LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

smtp authentication

Solved!
Go to solution

it works with .txt file but not with .pdf

 

it's very strange i don't understand why i can send .txt file but not a .pdf file.......

0 Kudos
Message 11 of 24
(3,347 Views)

I noticed that i can't send files larger than 90-100 KB

 

i got same result with the smtp server of gmail and mine......

 

0 Kudos
Message 12 of 24
(3,340 Views)

For text file attachments you do not have to set the MIME type. But for PDF files you have to. For example, create the Attachment object as follows:

 

char *pdfMimeTypeString = NULL;

/* other code */

errChk(System_Net_Mime_MediaTypeNames_Application__Get__Pdf(&pdfMimeTypeString, NULL));

errChk(System_Net_Mail_Attachment__Create_1(&attachment, "c:\\temp\\temp.pdf",   pdfMimeTypeString, NULL));

CDotNetFreeMemory(pdfMimeTypeString);

0 Kudos
Message 13 of 24
(3,333 Views)

is it correct the sequence of instructions??

 

 

errChk(System_Net_Mail_SmtpClient__Create_2(&smtpClient,SMTP, 587, NULL));

errChk(System_Net_Mail_SmtpClient_Set_EnableSsl(smtpClient,0, NULL));

errChk(System_Net_Mail_SmtpClient_Set_DeliveryMethod(smtpClient, 0x0, NULL));

errChk(System_Net_Mail_SmtpClient_Set_Timeout(smtpClient, 5000, NULL));

errChk(System_Net_NetworkCredential__Create_1(&credentials,USER,PASS,NULL));

errChk(System_Net_Mail_SmtpClient_Set_Credentials(smtpClient,(System_Net_ICredentialsByHost)credentials, NULL));

errChk(System_Net_Mail_MailMessage__Create_2(&message, from, to,subject,message_1, NULL));

errChk(System_Net_Mail_MailMessage_Get_Attachments(message, &attachments, NULL));

errChk(System_Net_Mime_MediaTypeNames_Application_​_Get__Pdf(&pdfMimeTypeString, NULL));

 

token=strtok(attach,SEPARATORE);

 

       while(token!=NULL)  { 

         

                errChk(System_Net_Mail_Attachment__Create_1(&attac​hment, "c:\\temp\\temp.pdf",   pdfMimeTypeString, NULL));

                errChk(System_Net_Mail_AttachmentCollection_Add(attachments, attachment, NULL)); 

                token=strtok(NULL,SEPARATORE);

       }  

 

CDotNetFreeMemory(pdfMimeTypeString);

errChk(System_Net_Mail_SmtpClient_Send_1(smtpClient, message, NULL));

 

 

0 Kudos
Message 14 of 24
(3,328 Views)

I'm having the same problem:

 

if i send a file(pdf,txt,ecc.) of 80-90 KB , it works.....

 

if i send a file(pdf,txt,ecc.) larger than 100 KB , it doesn't  work.....

 

0 Kudos
Message 15 of 24
(3,325 Views)

I am not sure why you cannot send larger files. That could be some limitation of the smtp server, your user account, or even the .NET library. I am not sure.

0 Kudos
Message 16 of 24
(3,318 Views)

Hello Mohan,

 

while i was testing my application i discoverd something interesting:

 

i noticed that without "System_Net_Mail_SmtpClient_Set_Timeout(smtpClient, 5000, NULL))"  i can send files up to 3 MB !!!!!!.

 

i think i can't send larger files , because they take a lot of time in upload so the connection fails.

is there any function that allow to maintain the connection for long???

 

what do you think about this supposition???

 

another thing, what does "0x0" mean in "System_Net_Mail_SmtpClient_Set_DeliveryMethod(smtpClient,0x0, NULL)" ???

 

last thing the "System_Net_Mail_SmtpClient_Send_1(smtpClient, message, NULL)" returns -6571 when i can't send mail.

 

 

 

0 Kudos
Message 17 of 24
(3,310 Views)
Solution
Accepted by Jimmy_Singh

Ah, the timeout affecting this makes sense.

The 0 in System_Net_Mail_SmtpClient_Set_DeliveryMethod maps to SmtpDeliveryMethod.Network and means that the email is sent to the smtp server via the network. SmtpDeliveryMethod is documented here:

http://msdn.microsoft.com/en-us/library/system.net.mail.smtpdeliverymethod.aspx

 

-6571 error code means 'the target invoked threw an exception' - use CDotNetGetErrorDescription to find out what a CVI .NET Library error code means. Send_1 is probably returning the error because it does not know the recepients, etc unless you set this in the MailMessage object by creating it using:

errChk(System_Net_Mail_MailMessage__Create_2(&mess​age, from, to, subject, body, NULL));

There could also be some other reason for the exception.

 

You can get more details about the exception by doing:

CDotNetHandle exception = NULL;

int error = System_Net_Mail_SmtpClient_Send_1(smtpClient, message, &exception);

if (error < 0 && exception != NULL) {

  char *exceptionMessage, *exceptionSource, *exceptionTrace, *exceptionSite, *exceptionHelpLink;

  CDotNetGetExceptionInfo(exception, NULL, &exceptionMessage, &exceptionSource,

    &exceptionTrace, &exceptionSite, &exceptionHelpLink);

  /* print or display exception details */

  if (exceptionMessage) CDotNetFreeMemory(exceptionMessage);

  if (exceptionSource) CDotNetFreeMemory(exceptionSource);

  if (exceptionTrace) CDotNetFreeMemory(exceptionTrace);

  if (exceptionSite) CDotNetFreeMemory(exceptionSite);

  if (exceptionHelpLink) CDotNetFreeMemory(exceptionHelpLink);

  CDotNetDiscardHandle(exception);

  exception = NULL;

}

Message 18 of 24
(3,220 Views)

THANKS FOR YOUR HUGE HELP!!!!!!!!!!!!!

 

i resolved the problem.

it was the "Timeout" problem:

i was considering "5000" in System_Net_Mail_SmtpClient_Set_Timeout() as 5000 second..........Smiley Happy

0 Kudos
Message 19 of 24
(3,209 Views)

Hello mohan,

 

is there any other function to discard .net object handle??

 

because when i have sent the mail(with atachments), i can't delete the sent file.

it gives me "access denied" because the file is open somewhere, but the mail is already sent. 

 

thanks.

0 Kudos
Message 20 of 24
(3,161 Views)