Re: [Programmatically Filling In Body of E-Mail Message]
Re: [Programmatically Filling In Body of E-Mail Message]
- Subject: Re: [Programmatically Filling In Body of E-Mail Message]
- From: j o a r <email@hidden>
- Date: Wed, 28 May 2003 08:33:30 +0200
Hej Rolf,
On Tuesday, May 27, 2003, at 22:20 Europe/Stockholm, Rolf wrote:
BTW: Its also possible to use NSMailDelivery. Unfortunately
NSMailDelivery does not seem to be documented anywhere. The following
transmits a simple mail:
< snip>
NSMailDelivery also supports file attachemnts, but I haven't got that
working.
NSMailDelivery is documented in the header file that you find in the
framework wrapper.
NSMailDeliver is under-powered IMO - it should really be possible to
reliably send email without having to rely on the user setting up
delivery accounts. I should be able to specify an SMTP host and
authentication information and send the message directly - not touching
the users' accounts.
Here is how I send a message with an image attachment:
- (void) sendEmailTo:(NSString *) to subject:(NSString *) subject
message:(NSString *) body imageData:(NSData *) imgData
imageName:(NSString *) imgName
{
// Create attributed string for body text
NSMutableAttributedString *aStr = [[[NSMutableAttributedString
alloc] initWithString: [NSString stringWithFormat: @"%@\n\n", body]]
autorelease];
// Create file wrapper for image
NSFileWrapper *fw = [[[NSFileWrapper alloc]
initRegularFileWithContents: imgData] autorelease];
// You need to provide a file name with the right file name suffix
for
// the image, to let the receiving mail client know how to deal
with the
// image data. For example "img.gif" for a GIF image.
[fw setPreferredFilename: imgName];
NSTextAttachment *ta = [[[NSTextAttachment alloc]
initWithFileWrapper: fw] autorelease];
NSAttributedString *imgStr = [NSAttributedString
attributedStringWithAttachment: ta];
// Append image
[aStr appendAttributedString: imgStr];
// Setup headers
NSMutableDictionary *headers = [NSMutableDictionary dictionary];
[headers setObject: to forKey: @"To"];
[headers setObject: subject forKey: @"Subject"];
[headers setObject: @"Apple Message Framework" forKey:
@"X-Mailer"];
[headers setObject: @"multipart/mixed" forKey: @"Content-Type"];
[headers setObject: @"1.0" forKey: @"Mime-Version"];
// Send message
BOOL didSend = [NSMailDelivery deliverMessage: aStr headers:
headers format: NSMIMEMailFormat protocol: nil];
if (!didSend)
{
NSRunAlertPanel(nil, @"Could not send mail - Crap!", nil, nil, nil);
}
}
j o a r
_______________________________________________
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.