Re: Sending Email with Attachments
Re: Sending Email with Attachments
- Subject: Re: Sending Email with Attachments
- From: TACKEL <email@hidden>
- Date: Fri, 24 Jan 2003 18:06:32 +0100
Hi,
It's really easy, the most difficult part is to send a file attached.
Take a look a the main function 'deliverMessage'. I forgot to tell you need to add the Message framework.
The messageBody is a NSAttributedString you just need to cast your NSMutableString or init the AttributtedString with it.
+ (BOOL)deliverMessage: (NSAttributedString *)messageBody headers: (NSDictionary *)messageHeaders format: (NSString *)messageFormat protocol: (NSString *)deliveryProtocol;
//
// messageBody is the actual contents of the message. If messageFormat is NSASCIIMailFormat,
// any rich text or attachments in messageBody will be lost
//
// messageHeaders contains all of the values that will appear in the message header,
// for example, "To", "From", "Subject", etc. If the value is an array, the elements
// in the array will converted to a comma seperated list of values in the message header
//
// messageFormat can be either NSASCIIMailFormat or NSMIMEMailFormat
//
// deliveryProtocol can be NSSMTPDeliveryProtocol
// or nil to use the platform's default deliveryProtocol (this is the preferred choice).
//
Regards,
Tackel
>
From: Joseph Jones <email@hidden>
>
Date: Fri, 24 Jan 2003 08:49:41 -0800
>
To: TACKEL <email@hidden>, Cocoa Dev <email@hidden>
>
Subject: Re: Sending Email with Attachments
>
>
This look sgreat, and would be perfect except for one thing: I am not
>
sending a file but am attaching a generated NSMutableString (as if it wer a
>
file). I realize I could write the file to disk, wrap it, attach it, send it
>
and then delete it but that sure seems like a lot of extra work. Any ideas
>
on how to do this w/o having to manage an external file?
>
>
Joe
>
>
>
> From: TACKEL <email@hidden>
>
> Date: Fri, 24 Jan 2003 17:33:22 +0100
>
> To: email@hidden, email@hidden
>
> Subject: Re: Sending Email with Attachments
>
>
>
> Hi Joseph,
>
>
>
> After some tries that works for me:
>
>
>
> BOOL sent;
>
> NSFileWrapper *fw=[NSFileWrapper alloc];
>
> NSTextAttachment *att= [NSTextAttachment alloc];
>
>
>
>
>
> [fw initWithPath: [@"~/Desktop/file.txt" stringByExpandingTildeInPath]];
>
> [att initWithFileWrapper:fw];
>
>
>
>
>
>
>
> NSMutableDictionary *headers;
>
> headers = [NSMutableDictionary dictionary];
>
> [headers setObject:@"tackel" forKey:@"From"];
>
> [headers setObject:@"email@hidden" forKey:@"To"];
>
> [headers setObject:@"Report" forKey:@"Subject"];
>
> [headers setObject:@"Apple Message" forKey:@"X-Mailer"];
>
> [headers setObject:@"multipart/mixed" forKey:@"Content-Type"];
>
> [headers setObject:@"1.0" forKey:@"Mime-Version"];
>
>
>
>
>
>
>
> sent= [NSMailDelivery deliverMessage: [NSAttributedString
>
> attributedStringWithAttachment: att] headers: headers format:
>
> NSMIMEMailFormat protocol: NSSMTPDeliveryProtocol];
>
>
>
> Hope it helps.
>
>
>
> Regards,
>
> Tackel.
>
>
>
>
>
>> From: Joseph Jones <email@hidden>
>
>> Date: Thu, 23 Jan 2003 22:21:29 -0800
>
>> To: Cocoa Dev Dev <email@hidden>
>
>> Subject: Sending Email with Attachments
>
>>
>
>> Can anyone point me to an example of sending email with attachments?
>
>> There was a thread on sending email here a while ago, though I can;t
>
>> seem to locate it in the archives.
>
>>
>
>> I have looked at EDMessage framework, and while it looks great I can
>
>> see no way of using it with an SMTP server that requires login (like
>
>> .Mac). I thought there was a simple way of sending mail using
>
>> NSWorkspace, but I don't know what it was... :-(
>
>>
>
>> Thanx,
>
>> joe
>
>> _______________________________________________
>
>> cocoa-dev mailing list | email@hidden
>
>> Help/Unsubscribe/Archives:
>
>> http://www.lists.apple.com/mailman/listinfo/cocoa-dev
>
>> Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.