无法通过邮件发送 csv 文件附件
我已使用 MFMailComposeViewController 发送生成的报告(csv)。
现在邮件已发送至 To:email id, &但是当我检查邮件时,我确实收到了邮件,但附件不存在。
然后我还尝试了 MailComposer 示例:
https://developer.apple.com /iphone/library/samplecode/MailComposer/index.html
其中 png 图像附加到邮件演示中。我也使用该应用程序发送邮件,但未发送相同结果的图像附件。
帮忙看看是什么问题? 提前致谢。
这是该应用程序中的代码:
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setSubject:@"Hello from California!"];
// Set up recipients
NSArray *toRecipients = [NSArray arrayWithObject:@"[email protected]"];
NSArray *ccRecipients = [NSArray arrayWithObjects:@"[email protected]", @"[email protected]", nil];
NSArray *bccRecipients = [NSArray arrayWithObject:@"[email protected]"];
[picker setToRecipients:toRecipients];
[picker setCcRecipients:ccRecipients];
[picker setBccRecipients:bccRecipients];
// Attach an image to the email
NSString *path = [[NSBundle mainBundle] pathForResource:@"rainy" ofType:@"png"];
NSData *myData = [NSData dataWithContentsOfFile:path];
[picker addAttachmentData:myData mimeType:@"image/png" fileName:@"rainy"];
// Fill out the email body text
NSString *emailBody = @"It is raining in sunny California!";
[picker setMessageBody:emailBody isHTML:NO];
[self presentModalViewController:picker animated:YES];
[picker release];
I have used the MFMailComposeViewController to send the generated report(csv).
Now mail is sent to To:email id, & but when i checked the mails i did received the mail but attachment was not there.
Then I also tried MailComposer example :
https://developer.apple.com/iphone/library/samplecode/MailComposer/index.html
in which the png image is attached to mail demo. I also sent mail using that app, But same result image attachment is not delivered.
Help, to find what's the problem?
Thanks in advance.
Here is code in that app :
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setSubject:@"Hello from California!"];
// Set up recipients
NSArray *toRecipients = [NSArray arrayWithObject:@"[email protected]"];
NSArray *ccRecipients = [NSArray arrayWithObjects:@"[email protected]", @"[email protected]", nil];
NSArray *bccRecipients = [NSArray arrayWithObject:@"[email protected]"];
[picker setToRecipients:toRecipients];
[picker setCcRecipients:ccRecipients];
[picker setBccRecipients:bccRecipients];
// Attach an image to the email
NSString *path = [[NSBundle mainBundle] pathForResource:@"rainy" ofType:@"png"];
NSData *myData = [NSData dataWithContentsOfFile:path];
[picker addAttachmentData:myData mimeType:@"image/png" fileName:@"rainy"];
// Fill out the email body text
NSString *emailBody = @"It is raining in sunny California!";
[picker setMessageBody:emailBody isHTML:NO];
[self presentModalViewController:picker animated:YES];
[picker release];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
在我的情况下,电子邮件从我的 iPhone 发送得很好,但从我妻子的 iPhone 发送时没有附件。事实证明,她的默认帐户设置为她的雅虎帐户,并且不允许附件。我只是将其切换到她的手机我的帐户,然后附件就制作好了。我用的是gmail,所以从来没有遇到过问题。
另外,我尝试将 MIME 类型从 text/csv 切换到 text/plain,但这没有帮助。无论哪种方式,它在我的 iPhone 上都有效,但在我妻子的 iPhone 上根本不起作用。
希望这有帮助!
In my situation the email was sent fine from my iPhone, but there was no attachment when sending from my wife's iPhone. Turns out that her default account was set to her Yahoo account and that was not allowing attachments. I simply switched it to her mobile Me account and the attachment was made. I use gmail so I never had a problem.
in addition, I had tried switching the MIME type from text/csv to text/plain and that did not help. It worked either way on my iPhone and not at all on my wife's.
Hope this helps!
我尝试附加带有“text/plain”和“text/plain”的 .csv 文件。我成功了。我想你也应该尝试一下。祝你好运。
I have tried to attach .csv file with "text/plain" & I got success. I think you should try the same. best of luck.
我遇到了同样的问题,我通过以下方式解决了问题
仔细查看我编写的两个函数:
一个从 .plist 文件定义文件名,另一个实际上设置
文件的位置(包括它的路径和文件名)。
使用正确的函数在 MFMailViewController 中检索文件名
已修复问题:
//----------------------------
//-------------- -----------
}
//-------------------------
最后一个是你要调用的函数你的 MFMailComposeViewController:
fileName 当然是一个 NSString,通过调用 fileName 函数检索:
NSString *文件名 = [自身文件名];
希望这有帮助!
I ran into the same problems and I fixed the problem by
doing a really hard look at two functions that I wrote:
One defines the filename from a .plist file, the other one actually sets the
location of the file (including it's path AND filename).
Using the right function to retrieve the filename in the MFMailViewController
fixed the issue:
//----------------------------
//-------------------------
}
//-------------------------
The last one is the function you want to call in your MFMailComposeViewController:
fileName, of course, is an NSString, retrieved by calling the fileName function:
NSString *fileName = [self fileName];
Hope this helps!
如果您的代码看起来没问题,我会怀疑
myData
没有加载数据nil
。放入NSLog([myData description])
或使用调试器检查myData
是否不nil
。If your code looks okay I'll suspect that that
myData
didn't get loaded with data isnil
. Put in anNSLog([myData description])
or use the debugger to check thatmyData
is notnil
.我没主意了。如果我陷入这种情况,我会使用您提供的示例代码创建一个独立的项目,看看是否可以让它工作。通常在这些情况下,您关注的代码可能是正确的,而错误来自其他地方。
另外:
fileName
设置为rainy.png
,即[picker addAttachmentData:myData mimeType:@"image/png" fileName:@"rainy.png “]
。祝你好运。
I'm out of ideas. If I was stuck in this situation I would create a stand alone project with the example code you provided and see if I could get it working. Usually in these situations the code you are focusing on is probably correct and error is coming from somewhere else.
Also:
fileName
torainy.png
, i.e.[picker addAttachmentData:myData mimeType:@"image/png" fileName:@"rainy.png"]
.Good luck.