2010-12-19 15 views
9

मुझे एक्शनमेलर का उपयोग करके अनुलग्नक के साथ ईमेल संदेश भेजने में समस्या है।ईमेल में अवैध फ़ाइल नाम (एक्शनमेलर)

यह बात है कि जब मैं जीमेल में अपना संदेश पढ़ता हूं तो मेरे अनुलग्नक में 'गैरनाम' फ़ाइल नाम होता है।

सूचक समारोह

class Notifier < ActionMailer::Base 
    def send_message 
    attachments["text.txt"] = {:content => "hello"} 
    mail(:to => "[email protected]", :subject => 'test') 
    end 
end 

संदेश हेडर:

 
Date: Sun, 19 Dec 2010 23:18:00 +0100 
Mime-Version: 1.0 
Content-Type: text/plain; 
charset=UTF-8; 
filename=text.txt 
Content-Transfer-Encoding: 7bit 
Content-Disposition: attachment; 
filename=text.txt 
Content-ID: ... 

कैसे मैं सही फ़ाइल नाम के साथ एक संदेश भेज सकते?

धन्यवाद

उत्तर

11

सुनिश्चित करें कि आप अपने विचार किया गया है।

app/views/[class_name]/[method_name]
में सही फ़ाइलों बनाओ एक app/views/notifier/send_message.erb फ़ाइल और app/views/notifier/send_message.html.erb फ़ाइल बनाएँ।

+0

वास्तव में आप इसे अधिक स्पष्ट करने के लिए 'send_message.text.erb' के रूप में दृश्य का नाम दे सकते हैं। –

+0

दो अलग-अलग फाइलें क्यों हैं जो एक ही काम करती हैं? – Trip

1

ड्रू सही है, यह समस्या तब होती है जब विशिष्ट मेलर दृश्य गुम हो जाता है।

आईएमएचओ, जीमेल को संदेश का एन्कोडिंग नहीं मिलता है और अनुलग्नक का नाम बदलता है।

अधिक जानकारी Gmail सहायता में उपलब्ध है:

0

मुझे लगता है कि जब आप, भागों प्राप्त ईमेल के लिए एक शरीर को परिभाषित नहीं करते अनुचित रूप से स्थापित किया गया है, और आप एक विशाल "गैरनाम" फ़ाइल जीतते हैं जिसमें सभी अनुलग्नकों के लिए पार्ट्स हेडर शामिल होते हैं।

Mailer.generic(attachments: [File.open('/path/to/file1.txt'), File.open('/path/to/file2.csv')]).deliver 

मैं, 2 अलग-अलग फ़ाइलों, सही नाम के साथ मिलती है, जब मैं यह कर:

class Mailer < ActionMailer::Base 
    def generic(args) 
    args.reverse_merge! to: '[email protected]', from: '[email protected]' 
    add_attachments! args.delete(:attachments) 
    mail(args) 
    end 

    protected 
    def add_attachments!(*files) 
    files.flatten.compact.each do |file| 
     attachments[File.basename(file)] = File.read(file) 
    end 
    end 
end 

मैं जब मैं यह करने के लिए एक नाम नहीं एकल फाइल मिलती है:

इस मेलर कोड का उपयोग करना

Mailer.generic(body: '', attachments: [File.open('/path/to/file1.txt'), File.open('/path/to/file2.csv')]).deliver 
संबंधित मुद्दे