07-10-2012 02:10 PM
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.......
07-11-2012 02:41 AM
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......
07-11-2012 09:00 AM
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);
07-11-2012 09:22 AM
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(&attachment, "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));
07-11-2012 10:14 AM
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.....
07-12-2012 09:14 AM
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.
07-13-2012 03:32 AM
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.
07-13-2012 09:40 AM - edited 07-13-2012 09:40 AM
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(&message, 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;
}
07-15-2012 06:01 AM
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..........
09-12-2012 05:16 AM
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.