I have been trying to use SKPSMTPMessage library.Although i have not yet succeeded would anyone let me know how i do not require to hardcode the sender of the mail.
What i have seen is we need to hardcode the sender in order to send the mail in SKPSMTPMessage. something like this :
SKPSMTPMessage *testMsg = [[SKPSMTPMessage alloc] init];
testMsg.fromEmail = #"youremail#email.com";
But i don't want a particular sender rather it should be the sender from the device.
Similar to one we have in mfmessagecomposeviewcontroller.
Also can i have the sender included in "CC/BCC" portion so as the sender as well receive's the copy of the mail he/she has sent.
Thank You.
You can achieve this, here are the base-steps:
- Create a screen/view which will collect all these informations (FromEmail, ToEmail, CC, BCC, SMTP Address, etc.)
- Save those details in your code.
- Use those details while sending out mail.
Hence it will make your code look like:
SKPSMTPMessage *testMsg = [[SKPSMTPMessage alloc] init];
testMsg.fromEmail = fromEmailTextField.text;
Hope this helps.
Related
Now that Apple's "Mail" app can be deleted in iOS 10 and using [MFMailComposeViewController canSendMail] is always return NO when Mail app is deleted.
Is there any alternative way for sending Mail from inside the app?
You can use the MailCore Framework. This is an alternative to MFMailComposeViewController. Using this framework you can send an email programmatically. You have to construct each and every field i.e, To,CC,BCC,Subject,body etc. by yourself using this. One important thing to remember it has no UI.
CTCoreMessage *msg = [[CTCoreMessage alloc] init];
[CTSMTPConnection sendMessage:msg server:[server stringValue] username:[username stringValue]
password:[password stringValue] port:[port intValue] useTLS:tls useAuth:auth];
[msg release];
I've been trying to implement an autocomplete UITEXTVIEW for my email app using this
https://github.com/hoteltonight/HTAutocompleteTextField
I would like to add the email addresses dynamically though. Is there any way to achieve the same. Because when I checked, the email addresses are initialised at start as given below.
HTEmailAutocompleteTextField.m
- (void)setupAutocompleteTextField
{
[super setupAutocompleteTextField];
// Default email domains to suggest
self.emailDomains = #[ #"gmail.com", #"yahoo.com"];
self.autocompleteDataSource = self;
}
The above method is called from HTAutocompleteTextField.m[- (void)awakeFromNib] as soon as the app is launched thereby not letting me to add email addresses dynamically.
Is there any work around because I get my email addresses later.
Any help is much appreciated.
Have you tried this from GitHub readme
HTAutocompleteTextField *textField = [[HTAutocompleteTextField alloc] initWithFrame:CGRectMake(0,0,100,31)];
The data source is the brains of the autocomplete logic. If you just want to autocomplete email addresses, use HTAutocompleteManager from the example project as follows:
textField.autocompleteDataSource = [HTAutocompleteManager sharedManager];
textField.autocompleteType = HTAutocompleteTypeEmail;
Alternatively, you may wish to create your own data source class and user the autocompleteType property to differentiate between fields with different data types. A HTAutocompleteTextFields's data source must implement the following method, as part of the HTAutocompleteDataSource protocol.
-(NSString *)textField:(HTAutocompleteTextField *)textField completionForPrefix:(NSString *)prefix ignoreCase:(BOOL)ignoreCase
I'm working with Xcode.
In my app I save some UIdocuments at that location
[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask];
I'm searching for a way to share documents, my first option is by email.
Can I send those documents by email, as an attachment? Can I open then with another device with the same app?
You could do like the following.
Create a MFMailComposeViewController and use - (void)addAttachmentData:(NSData*)attachment mimeType:(NSString*)mimeType fileName:(NSString*)filename method to add your attachment.
For example.
MFMailComposeViewController *mailVC = [[MFMailComposeViewController alloc] init];
[mailVC setSubject:#"Shared documents"];
[mailVC setToRecipients:#[#"sample#example.com"]];
[mailVC setMessageBody:#"Here the docs I want to share" isHTML:NO];
[mailComposer addAttachmentData:pdfData mimeType:#"application/pdf" fileName:#"file.pdf"];
[mailVC setMailComposeDelegate:self];
[self presentViewController:mailVC animated:YES completion:nil];
where pdfData is of type NSData. So, you need to transform your document into a NSData.
From Apple doc.
addAttachmentData:mimeType:fileName:
This method attaches the specified data after the message body but
before the user’s signature. You may attach multiple files (using
different file names) but must do so prior to displaying the mail
composition interface. Do not call this method after presenting the
interface to the user.
About the second part of your question. Could you explain what type of document do you need to display?
In the meantime, take a look at Adding "Open In..." option to iOS app.
To send any attachment you need to get the contents into an NSData object. If the document is on disk then this is simple. You just need the path or file URL to the document. Then you can create the NSData object using the path or URL.
If the receiver of the email has the same app and the app is setup to appear in the "Open In" menu for documents of this type, then the user can open the app from the attachment. Your app then just needs to know what to do when it is asked to open a file of this type. There are plenty of existing documentation and questions here on SO that describe how to register an app to open certain file types.
is there an alternative to MFMailComposeViewController that has more-or-less the same functionality, but that will let me handle the sending of the email myself, outside of Apples email-sending system?
What I want to do is to provide a nice email dialog, and then send it through a CRM system instead of directly from the iPad.
Cheers
Nik
YES, You can use the MailCore Framework. You can handle the sending of email by yourself. Before sending the mail you have to set its fields such as To,CC,BCC,Subject,body etc and then send by the following code..
CTCoreMessage *msg = [[CTCoreMessage alloc] init];
[CTSMTPConnection sendMessage:msg server:[server stringValue] username:[username stringValue]
password:[password stringValue] port:[port intValue] useTLS:tls useAuth:auth];
[msg release];
It works for me fine. Hope it will help you..
You will need to create your own email view and handler. You can use something like JSTokenField : https://github.com/jasarien/JSTokenField to get the functionality on the mail "To:" field.
I need to modify an existing project. In this project there are several (many) places where the app sends an email with preset text within it. The used function is
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:emailString]];
Which obviously opens iOS Mail, ready to send the message.
Now I need to include links in the body of the messages. Is it possible to do it without switching to MFMailComposeViewController in all that places? How?
it is very simple.
Each html tag should appended, use front slash before double quote in the url beginning and end
Example :
NSString *bodyText =#"<html>";
bodyText = [bodyText stringByAppendingString:#"<head>"];
bodyText = [bodyText stringByAppendingString:#"</head>"];
bodyText = [bodyText stringByAppendingString:#"<body>"];
bodyText = [bodyText stringByAppendingString:#"<a href=\"http://www.devaski.com\">My blog"];
bodyText = [bodyText stringByAppendingString:#"</a>"];
[mailComposer setMessageBody:bodyText isHTML:YES];
Have a look at this document - https://developer.apple.com/library/ios/#featuredarticles/iPhoneURLScheme_Reference/Articles/MailLinks.html#//apple_ref/doc/uid/TP40007892-SW1
The short answer, yes, you can pre-populate the body of the message by adding a body parameter to the URL (i.e mailto:john#apple.com?body=This%20goes%20to%20body). Notice though, that the string has to be properly escaped, which you can do easily with the help of NSString's stringByAddingPercentEscapesUsingEncoding:
I assume that any URL in the body that looks like a URL will be converted into a link by Mail app itself - not sure about that, test it out.