Re: How to send a mail from within a program
Re: How to send a mail from within a program
- Subject: Re: How to send a mail from within a program
- From: Lorenzo <email@hidden>
- Date: Thu, 10 Jul 2003 11:43:24 +0200
Hi,
in order to send emails from within your application do the following:
Be sure you configured the fields in the MacOS X panel
"System Preferences/Internet/Email"
otherwise it doesn't work.
// First compose a dictionary containing the headers ---------------
NSString *destinationAddress = @"email@hidden";
NSString *messageSubject = @"My first Email Subject";
NSMutableDictionary *messageHeaders;
messageHeaders = [[NSMutableDictionary alloc] init];
[messageHeaders setObject:destinationAddress forKey:@"To"];
[messageHeaders setObject:messageSubject forKey:@"Subject"];
// Then set the body of the message -------------------------------
NSString *bodyString = @"This is the body of my message";
NSAttributedString *messageBody;
messageBody = [[NSAttributedString alloc] initWithString:bodyString];
// Then send the email --------------------------------------------
BOOL ok;
ok = [NSMailDelivery deliverMessage:messageBody headers:messageHeaders
format:NSMIMEMailFormat protocol:NSSMTPDeliveryProtocol];
// Then release the objects you created ---------------------------
[messageBody release];
[messageHeaders release];
// ... and, don't send spam :-)
Best Regards
--
Lorenzo
email: email@hidden
>
Hello,
>
>
I am trying to find out how to send a mail from within a Cocoa
>
app. It is possible in that iCal can do it as an option when
>
a scheduled event happens, but there doesn't seem to be
>
any documentation on how to do it... I need to be able to
>
fully populate the "To:", "Subject:" and main body under
>
program control, is it possible?
>
>
Cheers,
>
>
Tim.
_______________________________________________
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.