Using MailKit to send through Outlook.com - asp.net-core

I'm trying to send an email through my Outlook.com email address using MailKit.
I've followed all the examples I've seen online and this is what I have:
public async Task SendEmailAsync(string email, string subject, string htmlmessage)
{
var message = new MimeMessage();
message.From.Add(new MailboxAddress("Service Account", "me#outlook.com"));
message.To.Add(new MailboxAddress("First Last", email));
message.Subject = subject;
message.Body = new TextPart(TextFormat.Html)
{
Text = htmlMessage
};
using (var client = new SmtpClient())
{
//Have tried both false and true
client.Connect("smtp-mail.outlook.com", 587, false);
client.AuthenticationMechanisms.Remove("XOAUTH2");
client.Authenticate("me#outlook.com", "mypassword");
await client.SendAsync(message);
client.Disconnect(true);
}
return;
}
If I set the useSSL parameter to true on client.Connect(), I get this error:
An error occurred while attempting to establish an SSL or TLS connection
If I set the useSSL parameter to false, I get this error:
AuthenticationException: AuthenticationInvalidCredentials: 5.7.3 Authentication unsuccessful
What am I doing wrong?
Update
Added ProtocolLogger per the suggestion of #jstedfast and here was the result:
Connected to smtp://smtp-mail.outlook.com:587/?starttls=when-available
S: 220 BN6PR11CA0009.outlook.office365.com Microsoft ESMTP MAIL Service ready at Sun, 10 Feb 2019 03:26:30 +0000
C: EHLO [192.168.1.12]
S: 250-BN6PR11CA0009.outlook.office365.com Hello [73.175.143.94]
S: 250-SIZE 157286400
S: 250-PIPELINING
S: 250-DSN
S: 250-ENHANCEDSTATUSCODES
S: 250-STARTTLS
S: 250-8BITMIME
S: 250-BINARYMIME
S: 250-CHUNKING
S: 250 SMTPUTF8
C: STARTTLS
S: 220 2.0.0 SMTP server ready
C: EHLO [192.168.1.12]
S: 250-BN6PR11CA0009.outlook.office365.com Hello [73.175.143.94]
S: 250-SIZE 157286400
S: 250-PIPELINING
S: 250-DSN
S: 250-ENHANCEDSTATUSCODES
S: 250-AUTH LOGIN XOAUTH2
S: 250-8BITMIME
S: 250-BINARYMIME
S: 250-CHUNKING
S: 250 SMTPUTF8
C: AUTH LOGIN
S: 334 ************
C: ****************
S: 334 ************
C: ****************
S: 535 5.7.3 Authentication unsuccessful [BN6PR11CA0009.namprd11.prod.outlook.com]
BTW, I commented out some stuff with *. I wasn't sure what that was and if it was sensitive or not.

It appears as though the code itself works. However, be aware that if you've set your account to require 2FA, you will get the error message above that indicates that your credentials are invalid. Be sure to disable 2FA!

If the problem you're facing is because of 2FA (2-factor Authentication) you should go to your Microsoft settings, in advanced settings you could request an "app password" once you receive it, you should use it instead of your email's password, worked for me.

try in this way:
client.Connect("smtp-mail.outlook.com", 587);
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential(From, Password);
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.EnableSsl = true;
You can also try client.ConnectType = SmtpConnectType.ConnectSSLAuto;
For MailKit
client.Connect("smtp-mail.outlook.com", 587, SecureSocketOptions.StartTls);
client.Authenticate("me#outlook.com", "mypassword");

I have been struggling with this issue myself for a new exchange online account (without 2FA). The account was for a customer and so I did not configure the account in my email client. After many attempts I added the account to my Outlook client and sent a test email. After that the issue was solved. Hope this will help others to solve the problem.

The AuthenticationException error means that the server is rejecting your user name and/or password.
Perhaps the username should be me instead of me#outlook.com?
Try getting a protocol log and seeing what type of authentication mechanism is being used.
https://github.com/jstedfast/MailKit/blob/master/FAQ.md#ProtocolLog

Related

ESP8226 micropython ssl connection issue with SMTP

So after doing a lot of research I have been able to send SMTP email using Google's gmail server. I am using the same code without issue in CPython on both Windows and Linux however when I try to use the code on Micropython 1.9.2 (Latest as of Sept 11th) on the ESP8266 or Unix port the code locks up on line 63 but I cannot figure out why.
Any recommendations on how to correct this would be greatly appreciated as I the only other thing I can think of is that Micropython's implementation of SSL is not sufficient and that I will need to attempt to port CPython SSL over.
Thank you.
Offending code is:
61 heloCommand = 'EHLO Alice\r\n'
62 ssl_clientSocket.write(heloCommand.encode())
63 recv1 = ssl_clientSocket.read(1024)
64 print(recv1)
CODE (Yes, I know it is ugly and plan to clean it up once working in micropython):
# Micropython
try:
import usocket as socket
#import base64
import ussl as ssl
except:
# Python version 3
import socket
#import base64
import ssl
msg = """From: XXX#gmail.com
To: XXX#gmail.com
Subject: Testing
Testing transmission thru python
"""
endmsg = "\r\n.\r\n"
recipient = "XXX#gmail.com"
sender = "XXX#gmail.com"
username = "XXX#gmail.com"
password = 'Mary_Had_A_Password_of_123'
# Choose a mail server (e.g. Google mail server) and call it mailserver
mailserver = "smtp.gmail.com"
port = 587
# Create socket called clientSocket and establish a TCP connection with mailserver
clientSocket = socket.socket()
clientSocket.connect(socket.getaddrinfo(mailserver, port)[0][-1])
recv = clientSocket.recv(1024)
print(recv)
print(recv[:3])
if recv[:3] != b'220':
print('220 reply not received from server.')
# Send HELO command and print server response.
heloCommand = 'EHLO Alice\r\n'
clientSocket.send(heloCommand.encode())
recv1 = clientSocket.recv(1024)
print(recv1)
if recv1[:3] != b'250':
print('250 reply not received from server.')
# Request an encrypted connection
startTlsCommand = 'STARTTLS\r\n'
clientSocket.send(startTlsCommand.encode())
tls_recv = clientSocket.recv(1024)
print(tls_recv)
if tls_recv[:3] != b'220':
print('220 reply not received from server')
# Encrypt the socket
#ssl_clientSocket = ssl.wrap_socket(clientSocket, ssl_version=ssl.PROTOCOL_TLSv1)
ssl_clientSocket = ssl.wrap_socket(clientSocket)
print("Secure socket created")
heloCommand = 'EHLO Alice\r\n'
ssl_clientSocket.write(heloCommand.encode())
recv1 = ssl_clientSocket.read(1024)
print(recv1)
# Send the AUTH LOGIN command and print server response.
authCommand = 'AUTH LOGIN\r\n'
ssl_clientSocket.write(authCommand.encode())
auth_recv = ssl_clientSocket.read(1024)
print(auth_recv)
if auth_recv[:3] != b'334':
print('334 reply not received from server')
print("Sending username / password")
# Send username and print server response.
#uname = base64.b64encode((username).encode())
uname=b'Base64EncryptedUser=='
pword=b'Base64EncryptedPassword'
print(str(uname))
ssl_clientSocket.write(uname)
ssl_clientSocket.write('\r\n'.encode())
uname_recv = ssl_clientSocket.read(1024)
print(uname_recv)
if uname_recv[:3] != b'334':
print('334 reply not received from server')
# Send password and print server response.
#pword = base64.b64encode((password).encode())
print(str(pword))
ssl_clientSocket.write(pword)
ssl_clientSocket.write('\r\n'.encode())
pword_recv = ssl_clientSocket.read(1024)
print(pword_recv)
if pword_recv[:3] != b'235':
print('235 reply not received from server')
# Send MAIL FROM command and print server response.
mailFromCommand = 'MAIL FROM: <' + sender + '>\r\n'
ssl_clientSocket.write(mailFromCommand.encode())
recv2 = ssl_clientSocket.read(1024)
print(recv2)
if recv2[:3] != b'250':
print('250 reply not received from server.')
# Send RCPT TO command and print server response.
rcptToCommand = 'RCPT TO: <' + recipient + '>\r\n'
ssl_clientSocket.write(rcptToCommand.encode())
recv3 = ssl_clientSocket.read(1024)
print(recv3)
if recv3[:3] != b'250':
print('250 reply not received from server.')
# Send DATA command and print server response.
dataCommand = 'DATA\r\n'
ssl_clientSocket.write(dataCommand.encode())
recv4 = ssl_clientSocket.read(1024)
print(recv4)
if recv4[:3] != b'354':
print('354 reply not received from server.')
# Send message data.
ssl_clientSocket.write(msg.encode())
# Message ends with a single period.
ssl_clientSocket.write(endmsg.encode())
recv5 = ssl_clientSocket.read(1024)
print(recv5)
if recv5[:3] != b'250':
print('250 reply not received from server.')
# Send QUIT command and get server response.
quitCommand = 'QUIT\r\n'
ssl_clientSocket.write(quitCommand.encode())
recv6 = ssl_clientSocket.read(1024)
print(recv6)
if recv6[:3] != b'221':
print('221 reply not received from server.')
clientSocket.close()
UPDATED CODE WITH ACCEPTED ANSWER (Yes, I know it is ugly) with read(1024) being replaced with readline() for ssl socket. Also needed to add a way to clean the buffer out after ssl EHLO command so added a "recvCount=recv1.decode().count('\n')" in first EHLO then a loop in the ssl EHLO for the same count:
# Micropython
try:
import usocket as socket
#import base64
import ussl as ssl
except:
# Python version 3
import socket
#import base64
import ssl
msg = """From: XXX#gmail.com
To: XXX#gmail.com
Subject: Testing
Testing transmission thru python
"""
endmsg = "\r\n.\r\n"
recipient = "XXX#gmail.com"
sender = "XXX#gmail.com"
username = "XXX#gmail.com"
password = 'Mary_Had_A_Password_of_123'
# Choose a mail server (e.g. Google mail server) and call it mailserver
mailserver = "smtp.gmail.com"
port = 587
# Create socket called clientSocket and establish a TCP connection with mailserver
clientSocket = socket.socket()
clientSocket.connect(socket.getaddrinfo(mailserver, port)[0][-1])
recv = clientSocket.recv(1024)
print(recv)
print(recv[:3])
if recv[:3] != b'220':
print('220 reply not received from server.')
# Send HELO command and print server response.
heloCommand = 'EHLO Alice\r\n'
clientSocket.send(heloCommand.encode())
recv1 = clientSocket.recv(1024)
recvCount=recv1.decode().count('\n')
print(recv1)
if recv1[:3] != b'250':
print('250 reply not received from server.')
# Request an encrypted connection
startTlsCommand = 'STARTTLS\r\n'
clientSocket.send(startTlsCommand.encode())
tls_recv = clientSocket.recv(1024)
print(tls_recv)
if tls_recv[:3] != b'220':
print('220 reply not received from server')
# Encrypt the socket
#ssl_clientSocket = ssl.wrap_socket(clientSocket, ssl_version=ssl.PROTOCOL_TLSv1)
ssl_clientSocket = ssl.wrap_socket(clientSocket)
print("Secure socket created")
heloCommand = 'EHLO Alice\r\n'
ssl_clientSocket.write(heloCommand.encode())
recv1=''
for index in range(0,recvCount):
recv1 = recv1+ssl_clientSocket.readline().decode()
print(recv1)
# Send the AUTH LOGIN command and print server response.
authCommand = 'AUTH LOGIN\r\n'
ssl_clientSocket.write(authCommand.encode())
auth_recv = ssl_clientSocket.readline()
print(auth_recv)
if auth_recv[:3] != b'334':
print('334 reply not received from server')
print("Sending username / password")
# Send username and print server response.
#uname = base64.b64encode((username).encode())
uname=b'Base64EncryptedUser=='
pword=b'Base64EncryptedPassword'
print(str(uname))
ssl_clientSocket.write(uname)
ssl_clientSocket.write('\r\n'.encode())
uname_recv = ssl_clientSocket.readline()
print(uname_recv)
if uname_recv[:3] != b'334':
print('334 reply not received from server')
# Send password and print server response.
#pword = base64.b64encode((password).encode())
print(str(pword))
ssl_clientSocket.write(pword)
ssl_clientSocket.write('\r\n'.encode())
pword_recv = ssl_clientSocket.readline()
print(pword_recv)
if pword_recv[:3] != b'235':
print('235 reply not received from server')
# Send MAIL FROM command and print server response.
mailFromCommand = 'MAIL FROM: <' + sender + '>\r\n'
ssl_clientSocket.write(mailFromCommand.encode())
recv2 = ssl_clientSocket.readline()
print(recv2)
if recv2[:3] != b'250':
print('250 reply not received from server.')
# Send RCPT TO command and print server response.
rcptToCommand = 'RCPT TO: <' + recipient + '>\r\n'
ssl_clientSocket.write(rcptToCommand.encode())
recv3 = ssl_clientSocket.readline()
print(recv3)
if recv3[:3] != b'250':
print('250 reply not received from server.')
# Send DATA command and print server response.
dataCommand = 'DATA\r\n'
ssl_clientSocket.write(dataCommand.encode())
recv4 = ssl_clientSocket.readline()
print(recv4)
if recv4[:3] != b'354':
print('354 reply not received from server.')
# Send message data.
ssl_clientSocket.write(msg.encode())
# Message ends with a single period.
ssl_clientSocket.write(endmsg.encode())
recv5 = ssl_clientSocket.readline()
print(recv5)
if recv5[:3] != b'250':
print('250 reply not received from server.')
# Send QUIT command and get server response.
quitCommand = 'QUIT\r\n'
ssl_clientSocket.write(quitCommand.encode())
recv6 = ssl_clientSocket.readline()
print(recv6)
if recv6[:3] != b'221':
print('221 reply not received from server.')
clientSocket.close()
recv1 = ssl_clientSocket.read(1024)
Please read about about MicroPython stream semantics (which closely matches Python stream semantics, just with some simplifications):
http://docs.micropython.org/en/latest/pyboard/library/uio.html?#conceptual-hierarchy
What the quoted statement does is requesting exactly 1024 of data (MicroPython follows "buffered stream" Python semantics by default). If there's not that much of data, .read() will patiently wait until enough arrives (or until EOF or error happens).
SMTP protocol is line-oriented, so you need to use .readline() instead.

sending mail through phpmailer error

helo guys i have been trying to send a mail through php script for the last 8 days first i was using the php mail() on the server it returned false after alot of searching then company told me they have disabled this feature and told me to use my gmail account for sending mail then i googled it and found phpmailer swiftmailer and other software finally i decided to use phpmailer and included 3-4 files on my root folder as described here(http://phpmailer.worxware.com/index.php?pg=install#) i used this code
<?php
require("class.phpmailer.php");
include('class.smtp.php');
$mail = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "smtp.gmail.com"; // SMTP server
$mail->SMTPDebug = 1; // enables SMTP debug information (for testing)
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->Port = 465; // set the SMTP port for the GMAIL server
$mail->SMTPSecure = 'ssl';
$mail->Username = "myid#gmail.com"; // SMTP account username
$mail->Password = "xxxxxxx"; // SMTP account password
$mail->From = "myid#gmail.com";
$mail->AddAddress("hostimf#gmail.com");
$mail->Subject = "First PHPMailer Message";
$mail->Body = "Hi! \n\n This is my first e-mail sent through PHPMailer.";
if(!$mail->Send()) {
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent.';
}
?>`
it is returning errors that are listed in my firefox browser like this
2015-07-24 20:12:02 CLIENT -> SERVER: EHLO localhost
2015-07-24 20:12:02 CLIENT -> SERVER: AUTH LOGIN
2015-07-24 20:12:03 CLIENT -> SERVER: c2lkZGhhbnRiYWh1Z3VuYUBnbWFpbC5jb20=
2015-07-24 20:12:03 CLIENT -> SERVER: Y2hpbXB1OTQ=
2015-07-24 20:12:04 SMTP ERROR: Password command failed: 534-5.7.14 Please log in via your web browser and 534-5.7.14 then try again. 534-5.7.14 Learn more at 534 5.7.14 https://support.google.com/mail/answer/78754 2sm16058566pdp.68 - gsmtp
2015-07-24 20:12:04 SMTP Error: Could not authenticate.
2015-07-24 20:12:04 CLIENT -> SERVER: QUIT
2015-07-24 20:12:04 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting Message was not sent.Mailer error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting`
this i tried on my wamp server
pls help me i m going mad trying to solve this problem pls help..... thanks

Mail sending failed using javamail : 550 5.7.1 Client does not have permissions to send as this sender

I am unable to setup my javamail session to send an email using my private mail service provider. I am using an auhenticated starttls session and am getting this error : 550 5.7.1 Client does not have permissions to send as this sender. Below is my mail session properties and debug trace :
mail.smtp.auth=true
mail.smtp.host=smtp.myprovider.com
mail.smtp.password=*****
mail.smtp.port=587
mail.smtp.starttls.enable=true
mail.smtp.user=****
javax.portlet.action[0] = sendMail
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "smtp.myprovider.com", port 587, isSSL false
220 smtp.myprovider.com Microsoft ESMTP MAIL Service ready at Tue, 2 Jun 2015 11:35:22 -0400
DEBUG SMTP: connected to host "smtp.myprovider.com", port: 587
EHLO sgmed001
250-smtp.myprovider.com Hello [xx.xx.xx.xx]
250-SIZE 52428800
250-PIPELINING
250-DSN
250-ENHANCEDSTATUSCODES
250-STARTTLS
250-AUTH NTLM
250-8BITMIME
250-BINARYMIME
250 CHUNKING
DEBUG SMTP: Found extension "SIZE", arg "52428800"
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "DSN", arg ""
DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
DEBUG SMTP: Found extension "STARTTLS", arg ""
DEBUG SMTP: Found extension "AUTH", arg "NTLM"
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: Found extension "BINARYMIME", arg ""
DEBUG SMTP: Found extension "CHUNKING", arg ""
STARTTLS
220 2.0.0 SMTP server ready
EHLO sgmed001
250-smtp.myprovider.com Hello [xx.xx.xx.xx]
250-SIZE 52428800
250-PIPELINING
250-DSN
250-ENHANCEDSTATUSCODES
250-AUTH NTLM LOGIN
250-8BITMIME
250-BINARYMIME
250 CHUNKING
DEBUG SMTP: Found extension "SIZE", arg "52428800"
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "DSN", arg ""
DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
DEBUG SMTP: Found extension "AUTH", arg "NTLM LOGIN"
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: Found extension "BINARYMIME", arg ""
DEBUG SMTP: Found extension "CHUNKING", arg ""
DEBUG SMTP: Attempt to authenticate
AUTH LOGIN
334 VXNlcm5hbWU6
****
334 UGFzc3dvcmQ6
***
235 2.7.0 Authentication successful
DEBUG SMTP: use8bit false
MAIL FROM:<sender#xx.xx>
250 2.1.0 Sender OK
RCPT TO:<recipient#xx.xx>
250 2.1.5 Recipient OK
DEBUG SMTP: Verified Addresses
DEBUG SMTP: recipient#xx.xx
DATA
354 Start mail input; end with <CRLF>.<CRLF>
Date: Tue, 2 Jun 2015 11:35:23 -0400 (EDT)
From: sender#xx.xx
To: recipient#xx.xx
Message-ID: <53119439.11433259323689.JavaMail>
Subject: Request
MIME-Version: 1.0
Content-Type: text/html;charset="UTF-8"
Content-Transfer-Encoding: 7bit
X-Auto-Response-Suppress: AutoReply, DR, NDR, NRN, OOF, RN
qweqwe
.
550 5.7.1 Client does not have permissions to send as this sender
com.sun.mail.smtp.SMTPSendFailedException: 550 5.7.1 Client does not have permissions to send as this sender
at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:1388)
at com.sun.mail.smtp.SMTPTransport.finishData(SMTPTransport.java:1215)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:586)
at com.liferay.util.mail.MailEngine._send(MailEngine.java:563)
at com.liferay.util.mail.MailEngine.send(MailEngine.java:350)
at com.liferay.util.mail.MailEngine.send(MailEngine.java:425)
at com.liferay.mail.messaging.MailMessageListener.doMailMessage(MailMessageListener.java:93)
at com.liferay.mail.messaging.MailMessageListener.doReceive(MailMessageListener.java:108)
at com.liferay.portal.kernel.messaging.BaseMessageListener.receive(BaseMessageListener.java:26)
at com.liferay.portal.kernel.messaging.InvokerMessageListener.receive(InvokerMessageListener.java:72)
at com.liferay.portal.kernel.messaging.ParallelDestination$1.run(ParallelDestination.java:69)
at com.liferay.portal.kernel.concurrent.ThreadPoolExecutor$WorkerTask._runTask(ThreadPoolExecutor.java:682)
at com.liferay.portal.kernel.concurrent.ThreadPoolExecutor$WorkerTask.run(ThreadPoolExecutor.java:593)
at java.lang.Thread.run(Thread.java:745)
11:35:23,696 ERROR [liferay/mail-1][MailEngine:77] null
com.sun.mail.smtp.SMTPSendFailedException: 550 5.7.1 Client does not have permissions to send as this sender_ [Sanitized]
at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:1388)
at com.sun.mail.smtp.SMTPTransport.finishData(SMTPTransport.java:1215)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:586)
at com.liferay.util.mail.MailEngine._send(MailEngine.java:563)
at com.liferay.util.mail.MailEngine.send(MailEngine.java:350)
at com.liferay.util.mail.MailEngine.send(MailEngine.java:425)
at com.liferay.mail.messaging.MailMessageListener.doMailMessage(MailMessageListener.java:93)
at com.liferay.mail.messaging.MailMessageListener.doReceive(MailMessageListener.java:108)
at com.liferay.portal.kernel.messaging.BaseMessageListener.receive(BaseMessageListener.java:26)
at com.liferay.portal.kernel.messaging.InvokerMessageListener.receive(InvokerMessageListener.java:72)
at com.liferay.portal.kernel.messaging.ParallelDestination$1.run(ParallelDestination.java:69)
at com.liferay.portal.kernel.concurrent.ThreadPoolExecutor$WorkerTask._runTask(ThreadPoolExecutor.java:682)
at com.liferay.portal.kernel.concurrent.ThreadPoolExecutor$WorkerTask.run(ThreadPoolExecutor.java:593)
at java.lang.Thread.run(Thread.java:745)
Ok thanks to Steffen I was able to work it out, see comment above. In short the real problem was that I tried to send a mail using a sender outside my mail provider space. Using a mail address inside my provider's space made the email go and be sent away.

When smtp mail returns a "password not accepted from server"

You get this error from phpmailer.
"Password not accepted from server: 535 Incorrect authentication data"
What causes this?
You must make sure that the Username given for the log-on is the same as the SetFrom email address.
This will return an error:
$mail->Username = "myemailaddress#gmail.com"; // GMAIL username
$mail->Password = "password"; // GMAIL password
$mail->SetFrom('mysetfromaddress#gmail.com', 'Pagelinks');
This should not.
$mail->Username = "mysetfromaddress#gmail.com"; // GMAIL username
$mail->Password = "password"; // GMAIL password
$mail->SetFrom('mysetfromaddress#gmail.com', 'Pagelinks');
When the Username and SetFrom do not match the authentication fails (according to an article found on Google).

error send email with phpmailer in server domain but succed in localhost

i have detail error with this problem,
SMTP -> FROM SERVER:220-server.modulindo.com ESMTP Exim 4.77 #2 Wed, 11 Jul 2012 10:57:22 +0700 220-We do not authorize the use of this system to transport unsolicited, 220 and/or bulk e-mail.
SMTP -> FROM SERVER: 250-server.modulindo.com Hello mail.modulindo.com [202.67.9.42] 250-SIZE 52428800 250-PIPELINING 250-AUTH PLAIN LOGIN 250 HELP
SMTP -> ERROR: Password not accepted from server: 535 Incorrect authentication data
SMTP -> FROM SERVER:250 Reset OK
please help me guys!?
i have a problem with phpmailer. i send email with phpmailer in localhost is succeed, but when i upload it in my server domain, there was an error happend. the error is..
SMTP Error: Could not authenticate. Mailer Error: SMTP Error: Could not authenticate.
this is my script..
....
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Mailer = "smtp";
$mail->Host = "ssl://smtp.gmail.com";
$mail->Port = 465;
$mail->SMTPAuth = true;
$mail->Username = "wasis85#gmail.com";
$mail->Password = "password";
$mail->From = "wasis85#gmail.com";
$mail->FromName = "Wasis Lukito";
$mail->AddAddress($ema[$ari_no],"wasis");
$mail->AddCC("wasisl85#yahoo.com");
$mail->AddReplyTo("wasisl85#yahoo.com","Wasis Lukito");
$mail->WordWrap = 50;
$mail->IsHTML(true);
$mail->Subject = "Penolakan Data BPLPSE";
$mail->Body = "Alasan di tolak ";
$mail->AltBody = "This research is supported by Google.com";
...
i solved same problem with comment (or cancel) this line
// $mail->IsSMTP();
this because from some server i had same error: SMTP Error: Could not authenticate (also Password is incorrect...etc)
The script seems to be fine. I believe you have to check and make sure if your server supports SMTP or it has been properly configured for SMTP or not.