Im trying to Send a random number though a email but i keep getting a error
Question: My code is an email code for a generating number to send via email

    
    
    msg = ('The number is',random.randrange(300,400),'Enjoy')
    

But I get this error:

    
    
    Traceback (most recent call last):
       line 30, in <module>
        server.sendmail(fromaddr, toaddrs, msg)
      File "C:\Python34\lib\smtplib.py", line 793, in sendmail
        (code, resp) = self.data(msg)
      File "C:\Python34\lib\smtplib.py", line 532, in data
        q = _quote_periods(msg)
      File "C:\Python34\lib\smtplib.py", line 168, in _quote_periods
        return re.sub(br'(?m)^\.', b'..', bindata)
      File "C:\Python34\lib\re.py", line 175, in sub
        return _compile(pattern, flags).sub(repl, string, count)
    TypeError: expected string or buffer
    


Answer: Your msg is a tuple , you can use `format()` of string to define a msg:

    
    
    >>> import random
    >>> msg = ('The number is',random.randrange(300,400),'Enjoy')
    >>> print msg
    ('The number is', 300, 'Enjoy')
    >>> msg = 'The number is {0}, Enjoy'.format(random.randrange(300, 400))
    >>> msg
    'The number is 325, Enjoy'
    

