Reputation: 149
I'm able to retrieve the value of a key in Firebase, in this case it's the user's email address but when I want to use it to compose an email, it does not show. Currently what is doing is picking up the default email address that is setup on the phone under Settings/Mail/Default account. Not sure what I'm missing or if this is possible. Any help is greatly appreciated.
VC
var userEmail: String!
override func viewDidLoad() {
super.viewDidLoad()
emailRef =
firestore.collection(NAME).document((self.test.documentId))
.collection(COMMENTS_REF).document()
if let emailId = Auth.auth().currentUser?.email {
userEmail = emailId
print("show address", userEmail)
}
}
inside the func to send email
let emailAction = UIAlertAction(title: "Email Comment - Internal",
style: .default) { (action) in
if MFMailComposeViewController.canSendMail() {
let mail = MFMailComposeViewController()
mail.mailComposeDelegate = self
mail.setPreferredSendingEmailAddress(self.userEmail!) //I can't get this to unwrap and add the user's email address.
print("TEST", self.userEmail!)
mail.setToRecipients([""])
mail.setSubject("Test Email")
mail.setMessageBody("Test", isHTML: true)
self.present(mail, animated: true)
}
When the app runs and the user wants to send an email, I need for the app to use the user's email address that was setup in firebase.
Upvotes: 0
Views: 130