Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot add attachment on iOS #109

Open
pirhano opened this issue Nov 19, 2018 · 1 comment
Open

Cannot add attachment on iOS #109

pirhano opened this issue Nov 19, 2018 · 1 comment

Comments

@pirhano
Copy link
Contributor

pirhano commented Nov 19, 2018

If you are creating an issue for a BUG please fill out this information. If you are asking a question or requesting a feature you can delete the sections below.

Failure to fill out this information will result in this issue being closed. If you post a full stack trace in a bug it will be closed, please post it to http://gist.github.com and then post the link here.

Bug Information

Version Number of Plugin: 5.2.0

Device Tested On: iPad v 12

Simulator Tested On:

Version of VS: 2017

Version of Xamarin: 4.11

Versions of other things you are using:

Steps to reproduce the Behavior

Expected Behavior

pop up email with attachment

Actual Behavior

the email setup without attachment

Code snippet

      _emailMessenger = CrossMessaging.Current.EmailMessenger;

        var email = new EmailMessageBuilder().To(to)
            .Subject(subject)
            .Body(body)
            .WithAttachment(zipPath, "application/zip")
            .Build();
        var fileEx = File.Exists(zipPath);
        if (_emailMessenger.CanSendEmail && _emailMessenger.CanSendEmailAttachments)
        {
            _emailMessenger.SendEmail(email);
        }

Screenshots

@Axemasta
Copy link

Firstly you should have verified the files existance before adding it to the email (are you 200% sure it exists). Secondly does the zip file have any spaces in it's name? I noticed an issue when trying to attach files with spaces in their name.

Here are examples on both platforms of valid & invalid file paths:

Valid

iOS :
/var/mobile/Containers/Data/Application/9C259542-E55C-471C-A0E0-E8B1D8F638F6/Documents/TimesheetMobileLogs.txt

Android :
/data/user/0/com.protirus.TimesheetApp/files/TimesheetMobileLogs.txt

Invalid

iOS :
/var/mobile/Containers/Data/Application/9C259542-E55C-471C-A0E0-E8B1D8F638F6/Documents/Timesheet Mobile Logs.txt

Android :
/data/user/0/com.protirus.TimesheetApp/files/Timesheet Mobile Logs.txt

I was completely unable to attach files with spaces in the name. Once I've acquired the file path I convert it to a URI and use the AbsolutePath property. Here is the method I am using to build the email.

public void OpenEmailWithAttachments(EmailFiles[] files)
{
    var filePaths = GetFilePaths(files);

    var emailer = CrossMessaging.Current.EmailMessenger;

    var email = new EmailMessageBuilder()
    .To("email@domain.com")
    .Subject(FormatEmailSubject())
    .Body(FormatEmailBody(files));

    foreach (var filePath in filePaths)
    {
        if (File.Exists(filePath.AbsolutePath))
        {
            email.WithAttachment(filePath.AbsolutePath, "file");       
        }
    }

    var builtEmail = email.Build();

    emailer.SendEmail(builtEmail);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants