You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Python从iCloud发邮件到Koodo短信网关显示成功但收不到问题咨询

问题:Python向Koodo彩信网关发送纯文本邮件失败

场景描述

Ecowitt气象站告警无法直接发送至手机短信(需验证码HTML邮件确认),因此先将告警转发至iCloud邮箱(接收正常),再通过Python代码获取邮件内容后转发至Koodo短信网关,但发送失败。

现象

  • Python代码执行无报错,SMTP服务器提示消息已接收
  • 向普通Hotmail地址发送邮件正常
  • 向Koodomobile.com彩信网关发送时,服务器显示接收成功,但手机端未收到短信/彩信

用户代码及执行结果

import imaplib
import email
from email.header import decode_header
from email import policy
from email.parser import BytesParser
import smtplib
from email.message import EmailMessage
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText

# Your credentials
username = "xxxxxxx@icloud.com"
password = "passwordapp"
recipient_number = "xxxxxxxxxx"  # Koodo number
sms_gateway = f"{recipient_number}@msg.koodomobile.com"
print (sms_gateway)

# Create the message
msg = MIMEText("Hello there ", "plain")  # <-- 'plain' ensures it's not HTML
msg["Subject"] = ""  # SMS gateways ignore subject
msg["From"] = username
msg["To"] = sms_gateway

print(msg.get_content_type())

# Send via SMTP (e.g., Gmail)
with smtplib.SMTP("smtp.mail.me.com", 587) as smtp:
    #smtp.connect("smtp.mail.me.com", 587)
    smtp.ehlo()
    smtp.starttls()
    smtp.ehlo()
    smtp.login(username, password)
    result =smtp.sendmail(username, sms_gateway, msg.as_string())
    if not result:
        print("✅ Message accepted by SMTP server")
    else:
        print("❌ Failed recipients:", result)

执行结果:

text/plain
✅ Message accepted by SMTP server

可能原因及解决方向

  • 网关地址验证:确认Koodo当前有效的网关地址,部分场景下需使用彩信网关[手机号]@mms.koodomobile.com替代短信网关msg.koodomobile.com,切换后测试。
  • 邮件内容规范:
    • 检查内容长度,Koodo单条短信限制约160字符,彩信约1000字符,避免超长内容被截断或拦截。
    • 移除内容中的特殊字符、异常换行,确保纯文本格式无格式错误。
  • SMTP发送优化:
    • 将邮件主题设为空格" "而非空字符串"",部分网关对空主题的邮件会做拦截处理。
    • 添加标准邮件头信息,模拟合规邮件格式:
      import datetime
      msg["Message-ID"] = f"<{username}.{datetime.datetime.now().timestamp()}@icloud.com>"
      msg["Date"] = email.utils.formatdate(localtime=True)
      
  • 发件人及邮箱验证:
    • 确保msg["From"]与SMTP登录的iCloud邮箱完全一致,避免网关判定发件人不符。
    • 直接用iCloud邮箱手动发送邮件到Koodo网关地址,确认是否能收到,排除Python代码以外的问题。
  • 退信检查:查看iCloud邮箱的垃圾邮件或退信文件夹,是否收到网关退回的邮件,获取具体拦截原因。

内容的提问来源于stack exchange,提问作者SRI_Techno

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.12 08:28:14