Re: Sending Email with Attachments
Re: Sending Email with Attachments
- Subject: Re: Sending Email with Attachments
- From: Joseph Jones <email@hidden>
- Date: Fri, 24 Jan 2003 18:46:50 -0800
This works perfectly:
- (void) sendEmailTo:(NSString*)to
subject:(NSString*)subject
attachment:(NSMutableString*)attachment
attachName:(NSString*)attachName
{
NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
NSString* smtpFromAddress = [defaults
stringForKey:PMXSMTPFromAddress];
BOOL sent;
NSMutableDictionary *headers;
NSFileWrapper* fw;
NSTextAttachment* ta;
NSAttributedString* msg;
fw = [[NSFileWrapper alloc] initRegularFileWithContents:[attachment
dataUsingEncoding:NSNonLossyASCIIStringEncoding]];
[fw setPreferredFilename:attachName];
ta = [[NSTextAttachment alloc] initWithFileWrapper:fw];
msg = [NSAttributedString attributedStringWithAttachment:ta];
headers = [NSMutableDictionary dictionary];
[headers setObject:smtpFromAddress forKey:@"From"];
[headers setObject:to forKey:@"To"];
[headers setObject:subject 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: msg
headers:headers
format:NSMIMEMailFormat
protocol: NSSMTPDeliveryProtocol];
[ta release];
[fw release];
if ( !sent )
{
//Error message here
}
}
Thank you all for your help!
joe
On Friday, January 24, 2003, at 08:49 AM, Joseph Jones wrote:
>
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
_______________________________________________
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.