以上就是给各位分享发送python电子邮件时添加excel文件附件,其中也会对python发送邮件带附件进行解释,同时本文还将给你拓展android–将XLS(Excel)文件附加到电子邮件、andr
以上就是给各位分享发送python电子邮件时添加excel文件附件,其中也会对python发送邮件带附件进行解释,同时本文还将给你拓展android – 将XLS(Excel)文件附加到电子邮件、android-通过电子邮件发送文本文件附件、asp.net – 添加电子邮件附件、PHP IMAP电子邮件附件无法访问某些电子邮件等相关知识,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!
本文目录一览:- 发送python电子邮件时添加excel文件附件(python发送邮件带附件)
- android – 将XLS(Excel)文件附加到电子邮件
- android-通过电子邮件发送文本文件附件
- asp.net – 添加电子邮件附件
- PHP IMAP电子邮件附件无法访问某些电子邮件
发送python电子邮件时添加excel文件附件(python发送邮件带附件)
使用python发送电子邮件时如何添加文档附件?我收到了要发送的电子邮件(请忽略:我正在循环发送电子邮件,每5秒发送一次,仅用于测试目的,我希望每30分钟发送一次,只需将5更改为1800)
到目前为止,这是我的代码。我如何从计算机上附加文档?
#!/usr/bin/python
import time
import smtplib
while True:
TO = 'xxxx@gmail.com'
SUBJECT = 'Python Email'
TEXT = 'Here is the message'
gmail_sender = 'xxxx@gmail.com'
gmail_passwd = 'xxxx'
server = smtplib.SMTP('smtp.gmail.com',587)
server.ehlo()
server.starttls()
server.ehlo()
server.login(gmail_sender,gmail_passwd)
BODY = '\n'.join([
'To: %s' % TO,'From: %s' % gmail_sender,'Subject:%s' % SUBJECT,'',TEXT
])
try:
server.sendmail(gmail_sender,[TO],BODY)
print 'email sent'
except:
print 'error sending mail'
time.sleep(5)
server.quit()
android – 将XLS(Excel)文件附加到电子邮件
我的应用程序使用intent方法向用户发送电子邮件,这是导出Excel电子表格数据(由JExcell API创建)的便捷方式.
该文件包含在名为records的文件夹中的SD卡上.
我试图发送的文件是call measurments.xls.
我已经在代码中测试了在发送之前是否存在该文件.电子邮件编辑器显示附件,但是当我发送然后接收电子邮件时,附件不存在.
但是,如果我将excel文件替换为png图像,则会收到附件.那是什么给了??
下面是我用来发送电子邮件的代码,它只是一个类中的一个短暂的静态方法.
public static void sendEmailWithAttachment(Context ctx, String to,String subject, String message, String fileAndLocation)
{
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("text/plain");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] {to});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, message);
File file = new File(fileAndLocation);
// File file = getFileStreamPath();
if (file.exists())
{
Log.v("Farmgraze", "Email file_exists!" );
}
else
{
Log.v("Farmgraze", "Email file does not exist!" );
}
Log.v("FarmGraze", "SEND EMAIL FileUri=" + Uri.parse("file:/"+ fileAndLocation));
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:/"+ fileAndLocation));
ctx.startActivity(Intent.createChooser(emailIntent, "Send mail..."));
}//end method
那么我需要做什么来接收xls文件?更改方法代码第二行中的mime类型?如果是这样的话.任何有用的建议将不胜感激.
谢谢阅读.
A.
解决方法:
好的人只是为这个问题添加闭包我找到了解决方案.
问题是发送到URI的文件路径String需要有三个正斜杠.
如:
file:///sdcard/somefolder/some_file.xls.
另外对于excel文档,需要设置类型如下:
emailIntent.setType("application/excel");
所以这个问题是双管齐下的.我知道通过this thread的三个斜线解决方案,但因为它没有工作认为问题在于其他地方.
此外,我通过this webpage了解了正确的mime类型,它列出了所有支持的mime类型,对于其他读者可能非常有用.
所以感谢您阅读并对我现在解决的小问题感兴趣.
android-通过电子邮件发送文本文件附件
我正在尝试附加文本文件以便通过电子邮件发送
但是每当我打开“电子邮件”应用程序时,都会说该文件不存在.
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("text/plain");
i.putExtra(Intent.EXTRA_EMAIL , new String[]{"musabyahya1005@gmail.com"});
i.putExtra(Intent.EXTRA_SUBJECT, "subject of email");
i.putExtra(Intent.EXTRA_TEXT , "body of email");
i.putExtra(Intent.EXTRA_STREAM, Uri.parse(directory+"/data.txt"));
try {
startActivity(Intent.createChooser(i, "Send mail..."));
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(getBaseContext(), "An Error Happened ", Toast.LENGTH_SHORT).show();
}
解决方法:
如果您尝试通过电子邮件发送文件,请确保它们位于公共可访问位置,并告诉您它是您要发送的文件.使用此代码作为示例.
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("message/rfc822").putExtra(Intent.EXTRA_EMAIL, new String[]{"fake@example.com"}).putExtra(android.content.Intent.EXTRA_SUBJECT, "Mail subject").putExtra(android.content.Intent.EXTRA_TEXT, "lalalala");
String targetFilePath = Environment.getExternalStorageDirectory().getPath() + File.separator + "tmp" + File.separator + "test.txt";
Uri attachmentUri = Uri.parse(targetFilePath);
emailIntent.putExtra(android.content.Intent.EXTRA_STREAM, Uri.parse("file://" + attachmentUri));
asp.net – 添加电子邮件附件
谢谢
<%@ Page Language="VB" ContentType="text/html" ResponseEncoding="ISO-8859-1" Debug="true" %> <% @Import Namespace="System.Web.Mail" %> <% @Import Namespace="IO" %> <script language="vb" runat="server"> Sub btnSendEmail_Click(sender as Object,e as EventArgs) Dim objMM as New MailMessage() objMM.To = "my@email.co.uk" objMM.From = "their@email.co.uk" objMM.BodyFormat = MailFormat.HTML objMM.Priority = MailPriority.normal objMM.Subject = "Attachment test" objMM.Body = "There should be an attachment with this email" objMM.Attachments.Add(new MailAttachment("myimage.jpg")) SmtpMail.SmtpServer = "localhost" SmtpMail.Send(objMM) End Sub </script> <html> <head> </head> <body> <form runat="server"> <asp:Button runat="server" id="btnSendEmail" Text="Send email" OnClick="btnSendEmail_Click" /> </form> </body> </html>
解决方法
new MailAttachment("myimage.jpg")
我怀疑你可能想要获得完整的路径,例如
new MailAttachment(Server.MapPath("Myimage.jpg"))
PHP IMAP电子邮件附件无法访问某些电子邮件
我正在尝试使用imap从电子邮件中获取电子邮件附件,
该脚本适用于大多数电子邮件,但一个发件人附件似乎有问题,无法检索PDF附件.
我的代码在这里
$hostname = '{mail.testserver.com:993/tls}INBox';
$username = 'test@testserver.nl';
$password = 's1M@F1225224';
/* try to connect */
$inBox = imap_open($hostname,$username,$password) or die('Cannot connect to Email Server: ' . imap_last_error());
/* grab emails */
$emails = imap_search($inBox,'FROM "info@test.com"');
count($emails);
/* if emails are returned, cycle through each... */
if($emails) {
/* begin output var */
$output = '';
$io=0;
/* put the newest emails on top */
rsort($emails);
/* for every email... */
foreach($emails as $email_number){
echo $io++;
echo '<br/>';
$int='';
/* get information specific to this email */
$overview = imap_fetch_overview($inBox,$email_number,0);
$message = imap_fetchbody($inBox,$email_number,1);
$headerx = imap_headerinfo($inBox,$email_number,0);
// get first mails header
$structure = imap_fetchstructure($inBox, $email_number);
//var_dump( $structure );
$attachments = array();
/* if any attachments found... */
if(isset($structure->parts) && count($structure->parts))
{
for($i = 0; $i < count($structure->parts); $i++)
{
echo 'dump of mail structure <pre>';
var_dump($structure->parts[$i]);
echo '<pre>';
$attachments[$i] = array(
'is_attachment' => false,
'filename' => '',
'name' => '',
'attachment' => ''
);
if($structure->parts[$i]->ifdparameters)
{
//dparameters
foreach($structure->parts[$i]->ifdparameters as $object)
{
echo $object->attribute;
if(strtolower($object->attribute) == 'filename')
{
$attachments[$i]['is_attachment'] = true;
$attachments[$i]['filename'] = $object->value;
}
}
}
if($structure->parts[$i]->ifparameters)
{
foreach($structure->parts[$i]->parameters as $object)
{
if(strtolower($object->attribute) == 'name')
{
$attachments[$i]['is_attachment'] = true;
$attachments[$i]['name'] = $object->value;
}
}
}
if($attachments[$i]['is_attachment'])
{
$attachments[$i]['attachment'] = imap_fetchbody($inBox, $email_number, $i+1);
/* 3 = BASE64 encoding */
if($structure->parts[$i]->encoding == 3)
{
$attachments[$i]['attachment'] = base64_decode($attachments[$i]['attachment']);
}
/* 4 = QUOTED-PRINTABLE encoding */
elseif($structure->parts[$i]->encoding == 4)
{
$attachments[$i]['attachment'] = quoted_printable_decode($attachments[$i]['attachment']);
}
}
}
}
echo '<pre>';
var_dump($attachments);
echo '<pre>';
break;
}
var dump of structure part $structure-> parts [$i]
object(stdClass)#36 (11) {
["type"]=>
int(1)
["encoding"]=>
int(0)
["ifsubtype"]=>
int(1)
["subtype"]=>
string(11) "ALTERNATIVE"
["ifdescription"]=>
int(0)
["ifid"]=>
int(0)
["ifdisposition"]=>
int(0)
["ifdparameters"]=>
int(0)
["ifparameters"]=>
int(1)
["parameters"]=>
array(1) {
[0]=>
object(stdClass)#78 (2) {
["attribute"]=>
string(8) "boundary"
["value"]=>
string(51) "--boundary_278_245b5f5d-6ca6-49f9-adc5-9723088add21"
}
}
["parts"]=>
array(2) {
[0]=>
object(stdClass)#74 (12) {
["type"]=>
int(0)
["encoding"]=>
int(4)
["ifsubtype"]=>
int(1)
["subtype"]=>
string(5) "PLAIN"
["ifdescription"]=>
int(0)
["ifid"]=>
int(0)
["lines"]=>
int(14)
["bytes"]=>
int(891)
["ifdisposition"]=>
int(0)
["ifdparameters"]=>
int(0)
["ifparameters"]=>
int(1)
["parameters"]=>
array(1) {
[0]=>
object(stdClass)#32 (2) {
["attribute"]=>
string(7) "charset"
["value"]=>
string(5) "utf-8"
}
}
}
[1]=>
object(stdClass)#49 (11) {
["type"]=>
int(1)
["encoding"]=>
int(0)
["ifsubtype"]=>
int(1)
["subtype"]=>
string(7) "RELATED"
["ifdescription"]=>
int(0)
["ifid"]=>
int(0)
["ifdisposition"]=>
int(0)
["ifdparameters"]=>
int(0)
["ifparameters"]=>
int(1)
["parameters"]=>
array(2) {
[0]=>
object(stdClass)#38 (2) {
["attribute"]=>
string(4) "type"
["value"]=>
string(9) "text/html"
}
[1]=>
object(stdClass)#67 (2) {
["attribute"]=>
string(8) "boundary"
["value"]=>
string(51) "--boundary_279_c12a0e86-9df1-42b4-a007-c75d5904de9f"
}
}
["parts"]=>
array(2) {
[0]=>
object(stdClass)#58 (12) {
["type"]=>
int(0)
["encoding"]=>
int(4)
["ifsubtype"]=>
int(1)
["subtype"]=>
string(4) "HTML"
["ifdescription"]=>
int(0)
["ifid"]=>
int(0)
["lines"]=>
int(43)
["bytes"]=>
int(3263)
["ifdisposition"]=>
int(0)
["ifdparameters"]=>
int(0)
["ifparameters"]=>
int(1)
["parameters"]=>
array(1) {
[0]=>
object(stdClass)#25 (2) {
["attribute"]=>
string(7) "charset"
["value"]=>
string(5) "utf-8"
}
}
}
[1]=>
object(stdClass)#69 (12) {
["type"]=>
int(5)
["encoding"]=>
int(3)
["ifsubtype"]=>
int(1)
["subtype"]=>
string(3) "PNG"
["ifdescription"]=>
int(0)
["ifid"]=>
int(1)
["id"]=>
string(15) ""
["bytes"]=>
int(16262)
["ifdisposition"]=>
int(0)
["ifdparameters"]=>
int(0)
["ifparameters"]=>
int(0)
["parameters"]=>
object(stdClass)#62 (0) {
}
}
}
}
}
}
object(stdClass)#66 (11) {
["type"]=>
int(1)
["encoding"]=>
int(0)
["ifsubtype"]=>
int(1)
["subtype"]=>
string(5) "MIXED"
["ifdescription"]=>
int(0)
["ifid"]=>
int(0)
["ifdisposition"]=>
int(0)
["ifdparameters"]=>
int(0)
["ifparameters"]=>
int(1)
["parameters"]=>
array(1) {
[0]=>
object(stdClass)#22 (2) {
["attribute"]=>
string(8) "boundary"
["value"]=>
string(51) "--boundary_281_2ef5384d-4be2-4276-b5be-0f73bcc0811d"
}
}
["parts"]=>
array(2) {
[0]=>
object(stdClass)#70 (13) {
["type"]=>
int(3)
["encoding"]=>
int(3)
["ifsubtype"]=>
int(1)
["subtype"]=>
string(3) "PDF"
["ifdescription"]=>
int(0)
["ifid"]=>
int(1)
["id"]=>
string(6) ""
["bytes"]=>
int(277524)
["ifdisposition"]=>
int(1)
["disposition"]=>
string(10) "attachment"
["ifdparameters"]=>
int(0)
["ifparameters"]=>
int(1)
["parameters"]=>
array(1) {
[0]=>
object(stdClass)#80 (2) {
["attribute"]=>
string(4) "name"
["value"]=>
string(15) "inv18701288.PDF"
}
}
}
[1]=>
object(stdClass)#63 (13) {
["type"]=>
int(3)
["encoding"]=>
int(3)
["ifsubtype"]=>
int(1)
["subtype"]=>
string(12) "OCTET-STREAM"
["ifdescription"]=>
int(0)
["ifid"]=>
int(1)
["id"]=>
string(6) ""
["bytes"]=>
int(77098)
["ifdisposition"]=>
int(1)
["disposition"]=>
string(10) "attachment"
["ifdparameters"]=>
int(0)
["ifparameters"]=>
int(1)
["parameters"]=>
array(1) {
[0]=>
object(stdClass)#55 (2) {
["attribute"]=>
string(4) "name"
["value"]=>
string(33) "Algemene Leveringsvoorwaarden.pdf"
}
}
}
}
}
var dump of attachments数组
array(2) {
[0]=>
array(4) {
["is_attachment"]=>
bool(false)
["filename"]=>
string(0) ""
["name"]=>
string(0) ""
["attachment"]=>
string(0) ""
}
[1]=>
array(4) {
["is_attachment"]=>
bool(false)
["filename"]=>
string(0) ""
["name"]=>
string(0) ""
["attachment"]=>
string(0) ""
}
}
有人知道这个电子邮件内容或脚本有什么问题,是否有任何获得附件的解决方案,非常感谢
我认为附件对象结构与其他邮件不同,但我不知道如何获取它
解决方法:
检查您尝试附加的文件的pdf附件的大小,它可能超过PHP.ini允许的限制
我们今天的关于发送python电子邮件时添加excel文件附件和python发送邮件带附件的分享就到这里,谢谢您的阅读,如果想了解更多关于android – 将XLS(Excel)文件附加到电子邮件、android-通过电子邮件发送文本文件附件、asp.net – 添加电子邮件附件、PHP IMAP电子邮件附件无法访问某些电子邮件的相关信息,可以在本站进行搜索。
本文标签: